Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using System;
- using System.Text.RegularExpressions;
- public class Register : MonoBehaviour
- {
- public GameObject username;
- public GameObject email;
- public GameObject password;
- public GameObject confPassword;
- private string Username;
- private string Email;
- private string Password;
- private string ConfPassword;
- private string form; //Pitää sisällään aikaisemmat muuttujat
- private bool EmailValid = false;
- 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",
- "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", "_", "-"};
- // Use this for initialization
- void Start()
- {
- }
- public void RegisterButton()
- {
- bool UN = false;
- bool EM = false;
- bool PW = false;
- bool CPW = false;
- if (Username != "")
- {
- 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
- {
- UN = true;
- }
- else
- {
- Debug.LogWarning("Username Taken");
- }
- }
- else
- {
- Debug.LogWarning("Username field Empty");
- }
- if (Email != "")
- {
- EmailValidation();
- if (EmailValid)
- {
- if (Email.Contains("@"))
- {
- if (Email.Contains("."))
- {
- EM = true;
- }
- else { Debug.LogWarning("Email is Incorrect"); }
- }
- else { Debug.LogWarning("Email is Incorrect"); }
- }
- else { Debug.LogWarning("Email is Incorrect"); }
- }
- else { Debug.LogWarning("Email Field Empty"); }
- if (Password != "")
- {
- if (Password.Length > 7)
- {
- PW = true;
- }
- else
- {
- Debug.LogWarning("Password Must Be atleast 8 Characters long");
- }
- }
- else
- {
- Debug.LogWarning("Password Field Empty");
- }
- if (ConfPassword != "")
- {
- if (ConfPassword == Password)
- {
- CPW = true;
- } else
- {
- Debug.LogWarning("Passwords Don't Match");
- }
- }
- else
- {
- Debug.LogWarning("Confirm Password Field Empty");
- }
- if (UN == true&&EM == true&&PW == true&&CPW == true) //Passwordin salaus
- {
- bool Clear = true;
- int i = 1;
- foreach(char c in Password)
- {
- if (Clear)
- {
- Password = "";
- Clear = false;
- }
- i++;
- char Encrypted = (char)(c * i);
- Password += Encrypted.ToString();
- }
- form = (Username +Environment.NewLine+ Email + Environment.NewLine + Password);
- 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
- username.GetComponent<InputField>().text = "";
- email.GetComponent<InputField>().text = "";
- password.GetComponent<InputField>().text = "";
- confPassword.GetComponent<InputField>().text = "";
- print("Registration Complete");
- }
- }
- // Update is called once per frame
- void Update()
- {
- if (Input.GetKeyDown(KeyCode.Tab))
- {
- if (username.GetComponent<InputField>().isFocused) //Tabilla voi hyppiä paikasta toiseen
- {
- email.GetComponent<InputField>().Select();
- }
- if (email.GetComponent<InputField>().isFocused)
- {
- password.GetComponent<InputField>().Select();
- }
- if (password.GetComponent<InputField>().isFocused)
- {
- confPassword.GetComponent<InputField>().Select();
- }
- }
- //Entteriä painamalla rekisteröityy
- if (Input.GetKeyDown(KeyCode.Return))
- {
- if (Password != "" && Email != ""&&Password != ""&&ConfPassword != "")
- {
- RegisterButton();
- }
- }
- Username = username.GetComponent<InputField>().text;
- Email = email.GetComponent<InputField>().text;
- Password = password.GetComponent<InputField>().text;
- ConfPassword = confPassword.GetComponent<InputField>().text;
- }
- void EmailValidation()
- {
- bool SW = false;
- bool EW = false;
- for (int i = 0; i < Characters.Length; i++)
- {
- if (Email.StartsWith(Characters[i]))
- {
- SW = true;
- }
- }
- for (int i = 0; i < Characters.Length; i++)
- {
- if (Email.EndsWith(Characters[i]))
- {
- EW = true;
- }
- }
- if (SW == true&&EW == true)
- {
- EmailValid = true;
- }
- else
- {
- EmailValid = false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement