Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Mastertrol · Mar 10, 2014 at 03:59 AM · serverdatabase

[Closed] www.data help

okay so basically I have a Database server up and online storing people's usernames and passwords. then I have another server PHP that is sending and retrieving that information form the database to unity's application to verify the username and password is correct. I found this script online but the problem is when I click login and it does if(w.data == "Correct") it doesn't do what it is suppose to do or for any of the other if(w.data) statment's pls help I need this to work. PS. I removed the URL Text so you don't know where my server is and how to access it.

Code:

 private var formNick = ""; //this is the field where the player will put the name to login
 private var formPassword = ""; //this is his password
 private var RformNick = ""; //this is the field where the player will put the name to login
 private var RformPassword = "";
 private var Remail = "";
 private var TRformPassword = "";
 public var guiSkin : GUISkin;
 public var pdata = "";
 
 var LoadOut : System.Boolean;
 var LoadOutText = "";
 var formText = ""; //this field is where the messages sent by PHP script will be in
 var URL = ""; //change for your URL
 // var hash = "812ca28212be5705ad52010bccc9ea3f"; //change your secret code, and remember to change into the PHP file too
 var DoLogin : System.Boolean;
 private var textrect = Rect (10, 150, 500, 500); //just make a GUI object rectangle
 
 
 function Start (){
 
 
     PlayerPrefs.DeleteAll();
 
 }
 function Load(){
     Debug.Log("Load");
     //if(w.text == "Correct"){
     //        Debug.Log("Work");
     //    }    
 
 }
 
 
 function OnGUI() {
 
     if(LoadOut){
 
         GUI.skin = guiSkin;
 
         GUI.Box (new Rect(Screen.width/2 - 150, Screen.height/2 - 30, 300, 60), LoadOutText);
 
 
     }else{
 
 
         GUI.Window (0, new Rect (Screen.width/2 - 250, Screen.height/2 - 150, 500, 400),Login, "");
 
 
     }
 
 
 }
 
 
 function Login (id : int){
     if(DoLogin){
         GUILayout.BeginVertical();
         GUI.skin = guiSkin;
         GUILayout.Box (/* new Rect (Screen.width/2 - 250, Screen.height/2 - 150, 500, 400),*/"Login");
         GUILayout.BeginHorizontal();
         GUILayout.FlexibleSpace();      
         GUILayout.Label( "Username:" ); //text with your nick
         formNick = GUILayout.TextField ( formNick , 15,  GUILayout.Width(345), GUILayout.Height(35));
         GUILayout.EndHorizontal();
         GUILayout.Space(10);
         GUILayout.BeginHorizontal();
         GUILayout.FlexibleSpace();  
         GUILayout.Label( "Password:" );
         formPassword = GUILayout.TextField (formPassword , 15,  GUILayout.Width(345), GUILayout.Height(35) ); //same as above, but for password
         GUILayout.EndHorizontal();
         GUILayout.Space(10);
         GUILayout.BeginHorizontal();
         GUILayout.Space(5); 
         if ( GUILayout.Button ("Login" ) ){ //just a button
             Action("Login");
 
 }
         if ( GUILayout.Button ( "Sign Up" ) ){ //just a button
             DoLogin = false;
 }
 
         GUILayout.EndHorizontal();
         GUILayout.EndVertical();
 }else{
 
         GUI.skin = guiSkin;
         GUILayout.Box ("Register");
         GUILayout.BeginHorizontal();
         GUILayout.FlexibleSpace();  
         GUILayout.Label("Username:" );
         RformNick = GUILayout.TextField (RformNick, 15,GUILayout.Width(300) ,GUILayout.Height(35)  );
         GUILayout.EndHorizontal();
         GUILayout.BeginHorizontal();
         GUILayout.FlexibleSpace();  
         GUILayout.Label("Password:" );
         RformPassword = GUILayout.TextField (RformPassword , 15,GUILayout.Width(300) , GUILayout.Height(35) );
         GUILayout.EndHorizontal();
         GUILayout.BeginHorizontal();
         GUILayout.FlexibleSpace();  
         GUILayout.Label("Password:" );
         TRformPassword = GUILayout.TextField (TRformPassword , 15,GUILayout.Width(300) , GUILayout.Height(35) );
         GUILayout.EndHorizontal();
         GUILayout.BeginHorizontal();
         GUILayout.FlexibleSpace();  
         GUILayout.Label("Email:" );
         Remail = GUILayout.TextField (Remail, 75,GUILayout.Width(300) , GUILayout.Height(35) );
         GUILayout.EndHorizontal();
         if ( GUILayout.Button ("Finish" ) ){ //just a button
             Action("Register");
 }
         if ( GUILayout.Button ("Back" ) ){ //just a button
             DoLogin = true;
 }
 
 }
 //GUI.TextArea( textrect, formText );
 
 
 }
 
 function Action(Act : String) {
 
     var form = new WWWForm(); //here you create a new form connection
     //add your hash code to the field myform_hash, check that this variable name is the same as in PHP file
     var tempURL : String; 
     if(Act =="Login"){
     tempURL = URL + "?User="+formNick+"&Pass="+formPassword+"&Act="+Act;
     }else{
     tempURL = URL + "?User="+RformNick+"&Pass="+RformPassword+"&Act="+Act+"&Email="+Remail;
 }
     var w = WWW(tempURL); //here we create a var called 'w' and we sync with our URL and the form
     yield w; //we wait for the form to check the PHP file, so our game dont just hang
     if (w.error != null) {
     print(w.error); //if there is an error, tell us
     } else {
     
     
     pdata = w.text;
     
     if(w.data == "    Correct"){
     print("Logging In...");
     LoadOut = true;
     LoadOutText = "Signing In...";
     yield WaitForSeconds(5);
     PlayerPrefs.SetString("RegUser",formNick);
     Load();
     Application.LoadLevel(1);    
     
 
 
 }
     if(w.data == "    Wrong"){
     LoadOut = true;
     LoadOutText = "Wrong Password";
     yield WaitForSeconds(3);
     LoadOut = false;
 
 
 }
     if(w.data == "    No User"){
     LoadOut = true;
     LoadOutText = "No Registered User Found";
     yield WaitForSeconds(3);
     LoadOut = false;
 }
     if(w.data == "    ILLEGAL REQUEST"){
     LoadOut = true;
     LoadOutText = "Server Error";
     yield WaitForSeconds(3);
     LoadOut = false;
 }
     if(w.data == "    Registered"){
     print("Account Created. Logging In.");
     LoadOut = true;
     LoadOutText = "Creating Account & Logging In...";
     PlayerPrefs.SetString("RegUser",RformNick);
     yield WaitForSeconds(5);
     Application.LoadLevel(1);
 }
     if(w.data == "    ERROR"){
     LoadOut = true;
     LoadOutText = "Login Error. Restarting.";
     yield WaitForSeconds(3);
     Application.LoadLevel(0);
 }
     print(w.data);
     LoadOut = true;
     LoadOutText = w.data;
     Load();
     //formText = w.data; //here we return the data our PHP told us
     w.Dispose(); //clear our form in game
 }
     formNick = ""; //just clean our variables
     formPassword = "";
 }
 
 function Update(){
 
     
 }
 
 

  
Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ShadoX · Mar 10, 2014 at 10:01 AM 0
Share

sorry, but " it doesn't do what it is suppose to do" isn't exactly a great problem description.. what exactly happens?

avatar image Mastertrol · Mar 12, 2014 at 02:49 AM 0
Share

What I mean it is like unity skips over the if statement checking whether it is correct or not when the Database return's correct or false.

if you need any more information contact me at mastertrolrs@gmail.com or here and I would be glad to give you more information.

avatar image Sildaekar · Mar 12, 2014 at 03:20 AM 0
Share

I found this script online

There's your problem, you shouldn't use scripts that you just find online. $$anonymous$$ost people write stuff tailored to their own projects and very rarely will they work "out of the box" in yours.

There are too many issues with this script to even begin. I'm not trying to sound mean or anything, but it would be best to just delete this file and code your own.

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

22 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

C# Capture Keypress 3 Answers

Expansion/Database help 2 Answers

php, sql security 3 Answers

In-Game GUI buttons don't work 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges