Advertisement
Guest User

accountregister

a guest
Sep 9th, 2017
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.23 KB | None | 0 0
  1. using System.Collections;
  2. using System.Security.Cryptography;
  3. using System.Text;
  4. using UnityEngine;
  5. using UnityEngine.SceneManagement;
  6. using UnityEngine.UI;
  7.  
  8. public class gameManagerLB : MonoBehaviour
  9. {
  10.     public InputField usernameBox;
  11.     public InputField passwordBox;
  12.     public InputField emailBox;
  13.     public Text rText;
  14.     public GameObject rTextObj;
  15.    
  16.     string CreateUserURL = "http://sigmastudios.tk/FlyingRocket/createFRAccount.php";
  17.  
  18.     public void createAccountButton ()
  19.     {
  20.         string usernameInput = usernameBox.text;
  21.         string passwordInput = passwordBox.text;
  22.         string emailInput = emailBox.text;
  23.  
  24.         if (Application.internetReachability == NetworkReachability.NotReachable)
  25.         {
  26.             rTextObj.SetActive(true);
  27.             rText.text = "No internet Connection. Is your WiFi on?";
  28.             return;
  29.         }
  30.         if (usernameInput == "" || passwordInput == "" || emailInput == "")
  31.         {
  32.             rTextObj.SetActive(true);
  33.             rText.text = "1 or more fields are blank.";
  34.             return;
  35.         }
  36.         if (Application.internetReachability == NetworkReachability.ReachableViaCarrierDataNetwork)
  37.         {
  38.             rTextObj.SetActive(true);
  39.             rText.text = "You cannot sign up with a Data Network. Try using WiFi.";
  40.             return;
  41.         } else
  42.         {
  43.             StartCoroutine(CreateAccount(usernameInput, passwordInput, emailInput));
  44.         }
  45.     }
  46.     public static byte[] GetHash(string inputString)
  47.     {
  48.         HashAlgorithm algorithm = SHA512.Create();
  49.         return algorithm.ComputeHash(Encoding.UTF8.GetBytes(inputString));
  50.     }
  51.     public static string GetHashString(string inputString)
  52.     {
  53.         StringBuilder sb = new StringBuilder();
  54.         foreach (byte b in GetHash(inputString))
  55.             sb.Append(b.ToString("x2"));
  56.  
  57.         return sb.ToString();
  58.     }
  59.     IEnumerator CreateAccount (string usernameInput, string passwordInput, string emailInput)
  60.     {
  61.         string hashKey = "createaccHashKey6501";
  62.         string hashx = "'" + usernameInput + "'" + "," + "'" + passwordInput + "'" + "," + "'" + emailInput + "'" + "," + "'" + hashKey + "'";
  63.         WWWForm requestCreateAccount = new WWWForm();
  64.         requestCreateAccount.AddField("usernamePost", usernameInput);
  65.         requestCreateAccount.AddField("passwordPost", passwordInput);
  66.         requestCreateAccount.AddField("emailPost", emailInput);
  67.         requestCreateAccount.AddField("hashPost", GetHashString(hashx));
  68.         WWW WWW = new WWW(CreateUserURL, requestCreateAccount);
  69.         yield return requestCreateAccount;
  70.        
  71.         InitializeLogin(usernameInput, passwordInput);      
  72.     }
  73.     public void InitializeLogin (string username, string password)
  74.     {
  75.         PlayerPrefs.SetString("username", username);
  76.         PlayerPrefs.SetString("password", password);
  77.         SceneManager.LoadScene("AccountManagement");
  78.      Debug.Log("Username: " + PlayerPrefs.GetString("username") + " Password: " + PlayerPrefs.GetString("password"));
  79.     }
  80.     public void ToMenu ()
  81.     {
  82.         SceneManager.LoadScene("MainMenu");
  83.     }
  84.     public void ToLogin ()
  85.     {
  86.         SceneManager.LoadScene("LoginPanel");
  87.     }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement