Advertisement
Guest User

Untitled

a guest
Feb 4th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.95 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using System;
  6. using System.Text.RegularExpressions;
  7.  
  8.  
  9. public class Register : MonoBehaviour
  10. {
  11.  
  12.  
  13. public GameObject username;
  14. public GameObject email;
  15. public GameObject password;
  16. public GameObject confPassword;
  17. private string Username;
  18. private string Email;
  19. private string Password;
  20. private string ConfPassword;
  21. private string form; //Pitää sisällään aikaisemmat muuttujat
  22. private bool EmailValid = false;
  23. private string[] Characters = { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "ä", "ö", "A", "B", "C", "D", "E",
  24. "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "Ä", "Ö", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "_", "-"};
  25.  
  26. // Use this for initialization
  27. void Start()
  28. {
  29.  
  30. }
  31.  
  32. public void RegisterButton()
  33. {
  34. bool UN = false;
  35. bool EM = false;
  36. bool PW = false;
  37. bool CPW = false;
  38.  
  39.  
  40. if (Username != "")
  41. {
  42. if (!System.IO.File.Exists(@"J:\Unity hommia ja projekteista poistettuja paskoja\Login_Harj_4.1_4.2\Assets\LoginDatabase\" + Username + ".txt")) //LoginDatabase kansio löytyy harjoituksen asseteista. Pitää tällä hetkellä manuaalisesti vaihtaa että homma toimii
  43. {
  44. UN = true;
  45. }
  46. else
  47. {
  48. Debug.LogWarning("Username Taken");
  49. }
  50. }
  51. else
  52. {
  53. Debug.LogWarning("Username field Empty");
  54. }
  55. if (Email != "")
  56. {
  57. EmailValidation();
  58. if (EmailValid)
  59. {
  60. if (Email.Contains("@"))
  61. {
  62. if (Email.Contains("."))
  63. {
  64. EM = true;
  65. }
  66. else { Debug.LogWarning("Email is Incorrect"); }
  67. }
  68. else { Debug.LogWarning("Email is Incorrect"); }
  69. }
  70. else { Debug.LogWarning("Email is Incorrect"); }
  71. }
  72. else { Debug.LogWarning("Email Field Empty"); }
  73.  
  74. if (Password != "")
  75. {
  76. if (Password.Length > 7)
  77. {
  78. PW = true;
  79. }
  80. else
  81. {
  82. Debug.LogWarning("Password Must Be atleast 8 Characters long");
  83. }
  84. }
  85. else
  86. {
  87. Debug.LogWarning("Password Field Empty");
  88. }
  89. if (ConfPassword != "")
  90. {
  91. if (ConfPassword == Password)
  92. {
  93. CPW = true;
  94. } else
  95. {
  96. Debug.LogWarning("Passwords Don't Match");
  97. }
  98. }
  99. else
  100. {
  101. Debug.LogWarning("Confirm Password Field Empty");
  102. }
  103. if (UN == true&&EM == true&&PW == true&&CPW == true) //Passwordin salaus
  104. {
  105. bool Clear = true;
  106. int i = 1;
  107. foreach(char c in Password)
  108. {
  109. if (Clear)
  110. {
  111. Password = "";
  112. Clear = false;
  113. }
  114. i++;
  115. char Encrypted = (char)(c * i);
  116. Password += Encrypted.ToString();
  117. }
  118. form = (Username +Environment.NewLine+ Email + Environment.NewLine + Password);
  119. System.IO.File.WriteAllText(@"J:\Unity hommia ja projekteista poistettuja paskoja\Login_Harj_4.1_4.2\Assets\LoginDatabase\" + Username + ".txt", form); //LoginDatabase kansio löytyy harjoituksen asseteista. Pitää tällä hetkellä manuaalisesti vaihtaa että homma toimii
  120. username.GetComponent<InputField>().text = "";
  121. email.GetComponent<InputField>().text = "";
  122. password.GetComponent<InputField>().text = "";
  123. confPassword.GetComponent<InputField>().text = "";
  124. print("Registration Complete");
  125.  
  126. }
  127. }
  128.  
  129. // Update is called once per frame
  130. void Update()
  131. {
  132. if (Input.GetKeyDown(KeyCode.Tab))
  133. {
  134. if (username.GetComponent<InputField>().isFocused) //Tabilla voi hyppiä paikasta toiseen
  135. {
  136. email.GetComponent<InputField>().Select();
  137. }
  138. if (email.GetComponent<InputField>().isFocused)
  139. {
  140. password.GetComponent<InputField>().Select();
  141. }
  142. if (password.GetComponent<InputField>().isFocused)
  143. {
  144. confPassword.GetComponent<InputField>().Select();
  145. }
  146. }
  147. //Entteriä painamalla rekisteröityy
  148. if (Input.GetKeyDown(KeyCode.Return))
  149. {
  150. if (Password != "" && Email != ""&&Password != ""&&ConfPassword != "")
  151. {
  152. RegisterButton();
  153. }
  154. }
  155.  
  156. Username = username.GetComponent<InputField>().text;
  157. Email = email.GetComponent<InputField>().text;
  158. Password = password.GetComponent<InputField>().text;
  159. ConfPassword = confPassword.GetComponent<InputField>().text;
  160. }
  161.  
  162. void EmailValidation()
  163. {
  164. bool SW = false;
  165. bool EW = false;
  166. for (int i = 0; i < Characters.Length; i++)
  167. {
  168. if (Email.StartsWith(Characters[i]))
  169. {
  170. SW = true;
  171. }
  172. }
  173. for (int i = 0; i < Characters.Length; i++)
  174. {
  175. if (Email.EndsWith(Characters[i]))
  176. {
  177. EW = true;
  178. }
  179. }
  180. if (SW == true&&EW == true)
  181. {
  182. EmailValid = true;
  183. }
  184. else
  185. {
  186. EmailValid = false;
  187. }
  188. }
  189. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement