Advertisement
Guest User

Client.lua

a guest
Mar 30th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.85 KB | None | 0 0
  1. --Variables--
  2. User = nil
  3. Pass = nil
  4. A = nil
  5. Init = nil
  6.  
  7. local function Reset()
  8. shell.run("clear")
  9. term.setBackgroundColor(colors.blue)
  10. term.clear()
  11. term.setTextColor(colors.white)
  12. textutils.slowPrint("Banking System")
  13. end
  14.  
  15. local function Login()
  16. term.setCursorPos(10 , 10)
  17. print("Username:")
  18. term.setCursorPos(10 , 11)
  19. print("Password:")
  20. term.setCursorPos(20 , 10)
  21. User = read()
  22. term.setCursorPos(20 , 11)
  23. Pass = read("*")
  24. end
  25.  
  26. local function Check()
  27. if fs.exists("disk/Users/"..User) == true then
  28. h = fs.open("disk/Users/"..User, "r")
  29. A = h.readAll() else
  30. Reset()
  31. term.setCursorPos(10 , 10)
  32. textutils.slowPrint("User does not exist")
  33. sleep(3)
  34. term.setCursorPos(10 , 10)
  35. term.clearLine()
  36. Login()
  37. end
  38. end
  39.  
  40. local function Verify()
  41. if A == Pass then
  42. Reset()
  43. term.setCursorPos(45 , 1)
  44. term.setTextColor(colors.green)
  45. print(""..User)
  46. term.setBackgroundColor(colors.blue)
  47. term.setTextColor(colors.white)
  48. term.setCursorPos(10 , 10) else
  49. Reset()
  50. term.setCursorPos(10 , 10)
  51. textutils.slowPrint("Incorrect password")
  52. sleep(2)
  53. term.setCursorPos(10 , 10)
  54. term.clearLine()
  55. shell.run("disk/Client.lua")
  56. end
  57. end
  58.  
  59. local function Initialize()
  60. local h = fs.open("disk/Init.lua", "r")
  61. Init = h.readAll()
  62. h.close()
  63. if Init == "true" then
  64. term.setCursorPos(1 , 8)
  65. textutils.slowPrint("Enter new credentials")
  66. sleep(2)
  67. Login()
  68. if fs.exists("disk/Users/"..User) == true then
  69. Reset()
  70. term.setCursorPos(10 , 10)
  71. textutils.slowPrint("Invalid Username")
  72. sleep(2)
  73. Reset()
  74. Initialize() else
  75. h = fs.open("disk/Users/"..User , "w")
  76. h.writeLine(""..Pass)
  77. h.close()
  78. Reset()
  79. term.setCursorPos(7 ,10)
  80. textutils.slowPrint("Computer will reboot to load credentials")
  81. sleep(3)
  82. fs.delete("disk/Init.lua")
  83. local h = fs.open("disk/Init.lua" , "w")
  84. h.writeLine("false")
  85. shell.run("reboot")
  86. end
  87. end
  88. end
  89.  
  90. Reset()
  91. Initialize()
  92. Login()
  93. Check()
  94. Verify()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement