Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- string loginCode="http://localhost/unity_db/login.php";
- string registerCode="http://localhost/unity_db/register.php";
- public string username="";
- public string password="";
- public string output="";
- void Start () {
- Debug.Log("print");
- }
- // Update is called once per frame
- void Update () {
- }
- void OnGUI()
- {
- GUI.Window (0, new Rect (Screen.width/4,Screen.height/4,Screen.width/2,Screen.height/2-5), LoginWindow, "Login");
- }
- void LoginWindow(int windowID)
- {
- GUI.Label (new Rect (140, 40, 130, 100), "Enter the Username");
- username = GUI.TextField (new Rect (25, 60, 375, 30), username);
- GUI.Label (new Rect (140, 92, 130, 100), "Enter the Password");
- password = GUI.TextField(new Rect (25, 115, 375, 30), password);
- if (GUI.Button (new Rect (29, 160, 175, 50), "Login"))
- StartCoroutine(handleLogin(username,password));
- GUI.Label (new Rect (55, 222, 250, 100),output);
- if(GUI.Button (new Rect (225, 160, 175, 50), "Register"))
- StartCoroutine(handleRegister(username,password));
- }
- IEnumerator handleLogin(string user,string pass)
- {
- /*if (username == "Achu" && password == "achu123") {
- Debug.Log (username + password);
- } else {
- Debug.Log ("error");
- }*/
- string login_url = loginCode + "?username=" + user + "&password=" + pass;
- WWW logindata = new WWW (login_url);
- yield return logindata;
- if (logindata.text == "right") {
- output="login successful";
- } else {
- output="invalid user pass";
- }
- }
- IEnumerator handleRegister(string user,string pass)
- {
- string register_url = registerCode + "?username=" + user + "&password=" + pass;
- WWW registerdata = new WWW (register_url);
- yield return registerdata;
- if(registerdata.text=="registered")
- {
- output="registration successful";
- }
- else{
- output="registration failed pass";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement