Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using System;
- using UnityEngine.SceneManagement;
- using System.Text.RegularExpressions;
- using UnityEngine.UI;
- public class Login : MonoBehaviour {
- public GameObject username;
- public GameObject password;
- private string Username;
- private string Password;
- private string[] Lines;
- private string decryptedPass;
- public void LoginButton()
- {
- bool UN = false;
- bool PW = 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;
- Lines = System.IO.File.ReadAllLines(@"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
- }
- else
- {
- Debug.LogWarning("Username Invalid");
- }
- }
- else
- {
- Debug.LogWarning("Username Field Empty");
- }
- if (Password != "")
- {
- 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
- {
- int i = 1;
- foreach (char c in Lines[2]){
- i++;
- char decrypted = (char)(c / i);
- decryptedPass += decrypted.ToString();
- }
- if (Password == decryptedPass)
- {
- PW = true;
- }
- else
- {
- Debug.LogWarning("Password Is Invalid");
- decryptedPass = "";
- }
- }
- else
- {
- Debug.LogWarning("Password Is Invalid");
- decryptedPass = "";
- }
- }
- else
- {
- Debug.LogWarning("Password Field Empty");
- decryptedPass = "";
- }
- if (UN == true && PW == true)
- {
- username.GetComponent<InputField>().text ="";
- password.GetComponent<InputField>().text ="";
- print("Login Succesful");
- SceneManager.LoadScene(1); //Lataa seuraavan näkymän loginin jälkeen , originaali vaihtoehto Application.LoadLevel("Start Menu");
- }
- }
- // Update is called once per frame
- void Update () {
- if (Input.GetKeyDown(KeyCode.Tab))
- {
- if (username.GetComponent<InputField>().isFocused) //Tabilla voi hyppiä paikasta toiseen
- {
- password.GetComponent<InputField>().Select();
- }
- }
- if (Input.GetKeyDown(KeyCode.Return))
- {
- if (Password != "" && Password != "")
- {
- LoginButton();
- }
- }
- Username = username.GetComponent<InputField>().text;
- Password = password.GetComponent<InputField>().text;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement