Advertisement
Bayarmagnai

Login

Jun 23rd, 2018
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.98 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 Login : MonoBehaviour {
  8.     public GameObject username;
  9.     public GameObject password;
  10.     public GameObject dialogue;
  11.     public String SceneAfterLogin;
  12.     private string Username;
  13.     private string Password;
  14.     private String[] Lines;
  15.     private string DecryptedPass;
  16.  
  17.     public void LoginButton(){
  18.         bool UN = false;
  19.         bool PW = false;
  20.         if (Username != ""){
  21.             if(System.IO.File.Exists(@"C:/UnityTestFolder/"+Username+".txt")){
  22.                 UN = true;
  23.                 Lines = System.IO.File.ReadAllLines(@"C:/UnityTestFolder/"+Username+".txt");
  24.             } else {
  25.                 Debug.LogWarning("Username Invaild");
  26.                 dialogue.SetActive(true);
  27.             }
  28.         } else {
  29.             Debug.LogWarning("Username Field Empty");
  30.             dialogue.SetActive(true);
  31.         }
  32.         if (Password != ""){
  33.             if (System.IO.File.Exists(@"C:/UnityTestFolder/"+Username+".txt")){
  34.                 int i = 1;
  35.                 foreach(char c in Lines[2]){
  36.                     i++;
  37.                     char Decrypted = (char)(c / i);
  38.                     DecryptedPass += Decrypted.ToString();
  39.                 }
  40.                 if (Password == DecryptedPass){
  41.                     PW = true;
  42.                 } else {
  43.                     Debug.LogWarning("Password Is invalid");
  44.                     dialogue.SetActive(true);
  45.                 }
  46.             } else {
  47.                 Debug.LogWarning("Password Is invalid");
  48.                 dialogue.SetActive(true);
  49.             }
  50.         } else {
  51.             Debug.LogWarning("Password Field Empty");
  52.             dialogue.SetActive(true);
  53.         }
  54.         if (UN == true&&PW == true){
  55.             username.GetComponent<InputField>().text = "";
  56.             password.GetComponent<InputField>().text = ""; 
  57.             print ("Login Sucessful");
  58.             Application.LoadLevel(SceneAfterLogin);
  59.         }
  60.     }
  61.     // Update is called once per frame
  62.     void Update () {
  63.         if (Input.GetKeyDown(KeyCode.Tab)){
  64.             if (username.GetComponent<InputField>().isFocused){
  65.                 password.GetComponent<InputField>().Select();
  66.             }
  67.         }
  68.         if (Input.GetKeyDown(KeyCode.Return)){
  69.             if (Password != ""&&Password != ""){
  70.                 LoginButton();
  71.             }
  72.         }
  73.         Username = username.GetComponent<InputField>().text;
  74.         Password = password.GetComponent<InputField>().text;   
  75.     }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement