Advertisement
Guest User

Untitled

a guest
Feb 4th, 2018
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.50 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using System;
  5. using UnityEngine.SceneManagement;
  6. using System.Text.RegularExpressions;
  7. using UnityEngine.UI;
  8.  
  9. public class Login : MonoBehaviour {
  10.  
  11. public GameObject username;
  12. public GameObject password;
  13. private string Username;
  14. private string Password;
  15. private string[] Lines;
  16. private string decryptedPass;
  17.  
  18. public void LoginButton()
  19. {
  20. bool UN = false;
  21. bool PW = false;
  22. if (Username != "")
  23. {
  24. 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
  25. {
  26. UN = true;
  27. 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
  28. }
  29. else
  30. {
  31. Debug.LogWarning("Username Invalid");
  32. }
  33. }
  34. else
  35. {
  36. Debug.LogWarning("Username Field Empty");
  37. }
  38. if (Password != "")
  39. {
  40. 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
  41. {
  42. int i = 1;
  43. foreach (char c in Lines[2]){
  44. i++;
  45. char decrypted = (char)(c / i);
  46. decryptedPass += decrypted.ToString();
  47. }
  48. if (Password == decryptedPass)
  49. {
  50. PW = true;
  51. }
  52. else
  53. {
  54. Debug.LogWarning("Password Is Invalid");
  55. decryptedPass = "";
  56. }
  57. }
  58. else
  59. {
  60. Debug.LogWarning("Password Is Invalid");
  61. decryptedPass = "";
  62. }
  63. }
  64. else
  65. {
  66. Debug.LogWarning("Password Field Empty");
  67. decryptedPass = "";
  68. }
  69. if (UN == true && PW == true)
  70. {
  71. username.GetComponent<InputField>().text ="";
  72. password.GetComponent<InputField>().text ="";
  73. print("Login Succesful");
  74. SceneManager.LoadScene(1); //Lataa seuraavan näkymän loginin jälkeen , originaali vaihtoehto Application.LoadLevel("Start Menu");
  75. }
  76. }
  77.  
  78. // Update is called once per frame
  79. void Update () {
  80.  
  81. if (Input.GetKeyDown(KeyCode.Tab))
  82. {
  83. if (username.GetComponent<InputField>().isFocused) //Tabilla voi hyppiä paikasta toiseen
  84. {
  85. password.GetComponent<InputField>().Select();
  86. }
  87. }
  88. if (Input.GetKeyDown(KeyCode.Return))
  89. {
  90. if (Password != "" && Password != "")
  91. {
  92. LoginButton();
  93. }
  94. }
  95. Username = username.GetComponent<InputField>().text;
  96. Password = password.GetComponent<InputField>().text;
  97. }
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement