Guest User

Untitled

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