Advertisement
Bayarmagnai

Register

Jun 23rd, 2018
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.04 KB | None | 0 0
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. using System.Collections;
  4. using System;
  5. using System.Text.RegularExpressions;
  6.  
  7. public class Register : MonoBehaviour {
  8.     public GameObject username;
  9.     public GameObject email;
  10.     public GameObject password;
  11.     public GameObject confPassword;
  12.     public GameObject dialogue;
  13.     public GameObject completeDialogue;
  14.     private string Username;
  15.     private string Email;
  16.     private string Password;
  17.     private string ConfPassword;
  18.     private string form;
  19.     private bool EmailValid = false;
  20.     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",
  21.                                    "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",
  22.                                    "1","2","3","4","5","6","7","8","9","0","_","-"};
  23.    
  24.     public void RegisterButton(){
  25.         bool UN = false;
  26.         bool EM = false;
  27.         bool PW = false;
  28.         bool CPW = false;
  29.  
  30.         if (Username != ""){
  31.             if (!System.IO.File.Exists(@"C:/UnityTestFolder/"+Username+".txt")){
  32.                 UN = true;
  33.             } else {
  34.                 Debug.LogWarning("Username Taken");
  35.                 dialogue.SetActive(true);
  36.             }
  37.         } else {
  38.             Debug.LogWarning("Username field Empty");
  39.             dialogue.SetActive(true);
  40.         }
  41.         if (Email != ""){
  42.             EmailValidation();
  43.             if (EmailValid){
  44.                 if(Email.Contains("@")){
  45.                     if(Email.Contains(".")){
  46.                         EM = true;
  47.                     } else {
  48.                         Debug.LogWarning("Email is Incorrect");
  49.                         dialogue.SetActive(true);
  50.                     }
  51.                 } else {
  52.                     Debug.LogWarning("Email is Incorrect");
  53.                     dialogue.SetActive(true);
  54.                 }
  55.             } else {
  56.                 Debug.LogWarning("Email is Incorrect");
  57.                 dialogue.SetActive(true);
  58.             }
  59.         } else {
  60.             Debug.LogWarning("Email Field Empty");
  61.             dialogue.SetActive(true);
  62.         }
  63.         if (Password != ""){
  64.             if(Password.Length > 5){
  65.                 PW = true;
  66.             } else {
  67.                 Debug.LogWarning("Password Must Be atleast 6 Characters long");
  68.                 dialogue.SetActive(true);
  69.             }
  70.         } else {
  71.             Debug.LogWarning("Password Field Empty");
  72.             dialogue.SetActive(true);
  73.         }
  74.         if (ConfPassword != ""){
  75.             if (ConfPassword == Password){
  76.                 CPW = true;
  77.             } else {
  78.                 Debug.LogWarning("Passwords Don't Match");
  79.                 dialogue.SetActive(true);
  80.             }
  81.         } else {
  82.             Debug.LogWarning("Confirm Password Field Empty");
  83.             dialogue.SetActive(true);
  84.         }
  85.         if (UN == true&&EM == true&&PW == true&&CPW == true){
  86.             bool Clear = true;
  87.             int i = 1;
  88.             foreach(char c in Password){
  89.                 if (Clear){
  90.                     Password = "";
  91.                     Clear = false;
  92.                 }
  93.                 i++;
  94.                 char Encrypted = (char)(c * i);
  95.                 Password += Encrypted.ToString();
  96.             }
  97.             form = (Username+Environment.NewLine+Email+Environment.NewLine+Password);
  98.             System.IO.File.WriteAllText(@"C:/UnityTestFolder/"+Username+".txt", form);
  99.             username.GetComponent<InputField>().text = "";
  100.             email.GetComponent<InputField>().text = "";
  101.             password.GetComponent<InputField>().text = "";
  102.             confPassword.GetComponent<InputField>().text = "";
  103.             print ("Registration Complete");
  104.             completeDialogue.SetActive(true);
  105.         }
  106.  
  107.     }
  108.    
  109.     // Update is called once per frame
  110.     void Update () {
  111.         if (Input.GetKeyDown(KeyCode.Tab)){
  112.             if (username.GetComponent<InputField>().isFocused){
  113.                 email.GetComponent<InputField>().Select();
  114.             }
  115.             if (email.GetComponent<InputField>().isFocused){
  116.                 password.GetComponent<InputField>().Select();
  117.             }
  118.             if (password.GetComponent<InputField>().isFocused){
  119.                 confPassword.GetComponent<InputField>().Select();
  120.             }
  121.         }
  122.         if (Input.GetKeyDown(KeyCode.Return)){
  123.             if (Password != ""&&Email != ""&&Password != ""&&ConfPassword != ""){
  124.                 RegisterButton();
  125.             }
  126.         }
  127.         Username = username.GetComponent<InputField>().text;
  128.         Email = email.GetComponent<InputField>().text;
  129.         Password = password.GetComponent<InputField>().text;
  130.         ConfPassword = confPassword.GetComponent<InputField>().text;
  131.     }
  132.  
  133.     void EmailValidation(){
  134.         bool SW = false;
  135.         bool EW = false;
  136.         for(int i = 0;i<Characters.Length;i++){
  137.             if (Email.StartsWith(Characters[i])){
  138.                 SW = true;
  139.             }
  140.         }
  141.         for(int i = 0;i<Characters.Length;i++){
  142.             if (Email.EndsWith(Characters[i])){
  143.                 EW = true;
  144.             }
  145.         }
  146.         if(SW == true&&EW == true){
  147.             EmailValid = true;
  148.         } else {
  149.             EmailValid = false;
  150.         }
  151.  
  152.     }
  153. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement