Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class LoginMenu : MonoBehaviour
- {
- //url of the login script, wich is server side.
- string loginURL = "http://127.0.0.1/login.php";
- //creation of the strings we use to log in.
- string userName = "";
- string passWord = "";
- string problem = "";
- //creating the int's for the height and width of the screen.
- int rectWidth = 430;
- int rectHeight = 240;
- //create the int to check if ppl spam the login button.
- int passTries = 0;
- //makes the big box for our menu.
- void OnGUI()
- {
- GUI.Window (0, new Rect((Screen.width - rectWidth) / 2, (Screen.height - rectHeight) / 2, rectWidth, rectHeight), LoginWindow, "Login");
- }
- //creates al the text fields and puts the in the right position.
- void LoginWindow(int windowID)
- {
- GUI.Label (new Rect(170, 40, 130, 100), "----Username----");
- userName = GUI.TextField(new Rect(30, 60, 375, 30), userName);
- GUI.Label (new Rect(170, 92, 130, 100), "----Password----");
- passWord = GUI.PasswordField(new Rect(30, 115, 375, 30), passWord, "*"[0], 25);
- //creates a login button and executes code when clicked
- if (GUI.Button (new Rect(25, 160, 175, 50), "Login"))
- {
- if (passTries >= 3)
- {
- problem = "Maximum tries of 3 reached, please wait 10 min";
- StartCoroutine(MaximumTries());
- }
- else
- {
- StartCoroutine(handleLogin(userName, passWord));
- }
- }
- //makes a register button and loads the register menu if clicked.
- if (GUI.Button (new Rect (225, 160, 175, 50), "Register"))
- {
- Application.LoadLevel ("Register");
- }
- //this displays the error if there is one.
- GUI.Label(new Rect(120, 210, 300, 100), problem);
- }
- //this send the info that is filled in to the login file on the server.
- IEnumerator handleLogin(string userNamez, string passWordz)
- {
- problem = "Checking username and password....";
- string login_URL = loginURL + "?username=" + userNamez + "&password=" + passWordz;
- WWW loginReader = new WWW (login_URL);
- yield return loginReader;
- if (loginReader.error != null)
- {
- problem = "Could not locate page";
- }
- else
- {
- if (loginReader.text == "right")
- {
- problem = "logged in";
- }
- else
- {
- problem = " invalid user/pass";
- passTries += 1;
- }
- }
- }
- //this disables the login if people have spammed the login button with the wrong password for more than 3 tries
- IEnumerator MaximumTries()
- {
- yield return new WaitForSeconds(1);// set to 600 when putting in the game
- passTries = 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement