Advertisement
Guest User

Untitled

a guest
Jun 30th, 2012
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.93 KB | None | 0 0
  1. -- Variables
  2.  
  3. local userauth = "debug"
  4. local passauth = "debug"
  5. local fullauth = 0
  6. local admin = false
  7.  
  8. -- Functions start here
  9.  
  10. function signin()
  11. while true do
  12. sleep(1)
  13. cls()
  14. print("Enter your credentials to sign in.")
  15. print(" ")
  16. print("Username: ")
  17. print("Password: ")
  18. term.setCursorPos(11,3)
  19. local username = read()
  20. globaluser = username
  21. term.setCursorPos(11,4)
  22. local password = read("*")
  23.     if fs.exists("appsupport/passwordlock/users/"..username) then
  24.     userauth = "pass"
  25.     else
  26.     userauth = "fail"
  27.     end
  28.     if userauth == "pass" then
  29.         if fs.exists("appsupport/passwordlock/users/"..username.."/password.txt") then
  30.         -- good file found
  31.         else
  32.         term.setCursorPos(1,6)
  33.         print("Account incorrectly configured! Contact an administrator.")
  34.         end
  35.     passcheck = fs.open("appsupport/passwordlock/users/"..username.."/password.txt", "r")
  36.         if userauth == "pass" then
  37.             if password == (passcheck.readAll()) then
  38.             passcheck.close()
  39.             passauth = "pass"
  40.             break
  41.             else
  42.             passauth = "fail"
  43.             term.setCursorPos(1,6)
  44.             print("Incorrect username or password.")
  45.             end    
  46.         end
  47.     end
  48. end
  49. end
  50.  
  51. function admintoolsconsole()
  52. cls()
  53. print("Tools")
  54. print(" ")
  55. print(" [ Console ] ")
  56. print("   Settings ")
  57. print("   Manage Users  ")
  58. print("   Shutdown Computer ")
  59. print(" ")
  60. print("  Access the console, you'll need to reboot to access this menu again.")
  61. local event, param1 = os.pullEvent()
  62. if param1 == 200 then
  63. admintoolssd()
  64. elseif param1 == 208 then
  65. admintoolssettings()
  66. elseif param1 == 28 then
  67. -- Nothing, let them into console.
  68. end
  69. end
  70.  
  71. function admintoolssettings()
  72. cls()
  73. print("Tools")
  74. print(" ")
  75. print("   Console  ")
  76. print(" [ Settings ]")
  77. print("   Manage Users  ")
  78. print("   Shutdown Computer ")
  79. print(" ")
  80. print("  Change your security settings.")
  81. local event, param1 = os.pullEvent()
  82. if param1 == 200 then
  83. admintoolsconsole()
  84. elseif param1 == 208 then
  85. admintoolsusers()
  86. elseif param1 == 28 then
  87. settingsmenu1()
  88. end
  89. end
  90.  
  91. function admintoolsusers()
  92. cls()
  93. print("Tools")
  94. print(" ")
  95. print("   Console  ")
  96. print("   Settings ")
  97. print(" [ Manage Users ] ")
  98. print("   Shutdown Computer ")
  99. print(" ")
  100. if admin == true then
  101. print("  Manage the other users on your computer.")
  102. else
  103. print("  You do not have permission to access this.")
  104. end
  105. local event, param1 = os.pullEvent()
  106. if param1 == 200 then
  107. admintoolssettings()
  108. elseif param1 == 208 then
  109. admintoolssd()
  110. elseif param1 == 28 then
  111.     if admin == true then
  112.     -- this happens
  113.     elseif admin == false then
  114.     -- this happens
  115.     end
  116. end
  117. end
  118.  
  119.  
  120. function admintoolssd()
  121. cls()
  122. print("Tools")
  123. print(" ")
  124. print("   Console   ")
  125. print("   Settings ")
  126. print("   Manage Users  ")
  127. print(" [ Shutdown Computer ] ")
  128. print(" ")
  129. print("  This will shutdown your computer.")
  130. local event, param1 = os.pullEvent()
  131. if param1 == 200 then
  132. admintoolsusers()
  133. elseif param1 == 208 then
  134. admintoolsconsole()
  135. elseif param1 == 28 then
  136. os.shutdown()
  137. end
  138. end
  139.  
  140. function settingsmenu1()
  141. cls()
  142. print("Settings Menu")
  143. print(" ")
  144. print(" [ Change Password ] ")
  145. print("   Change Username   ")
  146. print(" ")
  147. print("   Return to Tools Menu  ")
  148. local event, param1 = os.pullEvent()
  149. if param1 == 200 then
  150. --()
  151. elseif param1 == 208 then
  152. settingsmenu2()
  153. elseif param1 == 28 then
  154. changepass()
  155. end
  156. end
  157.  
  158. function settingsmenu2()
  159. cls()
  160. print("Settings Menu")
  161. print(" ")
  162. print("   Change Password  ")
  163. print(" [ Change Username ]  ")
  164. print(" ")
  165. print("   Return to Tools Menu  ")
  166. local event, param1 = os.pullEvent()
  167. if param1 == 200 then
  168. settingsmenu1()
  169. elseif param1 == 208 then
  170. settingsmenu3()
  171. elseif param1 == 28 then
  172. changeuser()
  173. end
  174. end
  175.  
  176. function settingsmenu3()
  177. cls()
  178. print("Settings Menu")
  179. print(" ")
  180. print("   Change Password  ")
  181. print("   Change Username   ")
  182. print(" ")
  183. print(" [ Return to Tools Menu ] ")
  184. local event, param1 = os.pullEvent()
  185. if param1 == 200 then
  186. settingsmenu2()
  187. elseif param1 == 208 then
  188. settingsmenu1()
  189. elseif param1 == 28 then
  190. admintoolssettings()
  191. end
  192. end
  193.  
  194.  
  195. function changepass()
  196. cls()
  197. write("Enter a new password here: ")
  198. changepass = read()
  199. fs.delete("appsupport/passwordlock/users/"..globaluser.."/password.txt")
  200. passchange = fs.open("appsupport/passwordlock/users/"..globaluser.."/password.txt", "w")
  201. passchange.writeLine(changepass)
  202. passchange.close()
  203. print("Password changed to '"..changepass.."'.")
  204. sleep(2)
  205. settingsmenu1()
  206. end
  207.  
  208. function changeuser()
  209. cls()
  210. write("Enter a new username here: ")
  211. changeuser = read()
  212. print(" ")
  213. write("Changing some files.")
  214. fs.makeDir("appsupport/passwordlock/temppass")
  215. sleep(.3)
  216. write(".")
  217. fs.copy("appsupport/passwordlock/users/"..globaluser.."/password.txt", "appsupport/passwordlock/temppass")
  218. sleep(.3)
  219. write(".")
  220. fs.delete("appsupport/passwordlock/users/"..globaluser)
  221. sleep(.3)
  222. write(".")
  223. fs.makeDir("appsupport/passwordlock/user/"..changeuser)
  224. sleep(.3)
  225. write(".")
  226. fs.copy("appsupport/passwordlock/temppass/password.txt", "appsupport/passwordlock/users/"..globaluser.."/password.txt")
  227.     if admin == true then
  228.     fs.delete("appsupport/passwordlock/admins/"..globaluser)
  229.     fs.makeDir("appsupport/passwordlock/admins/"..changeuser)
  230.     end
  231. globaluser = changeuser
  232. print("Username changed to '"..changeuser.."'.")
  233. sleep(2)
  234. settingsmenu2()
  235. end
  236.  
  237.  
  238. function cls()
  239. term.clear()
  240. term.setCursorPos(1,1)
  241. end
  242.  
  243. -- Functions stop here
  244.  
  245. cls()
  246.  
  247. -- Check for new users
  248.  
  249. if fs.exists("appsupport/passwordlock/users") then
  250. -- Users file found
  251. else   
  252. cls()
  253. print("It looks like this is your first time using this program.")
  254. print(" ")
  255. write("Please enter the username you'd like: ")
  256. local newuser = read()     
  257. fs.makeDir("appsupport/passwordlock/users")
  258. fs.makeDir("appsupport/passwordlock/users/"..newuser)
  259.     while true do
  260.     cls()
  261.     write("Please set a password for your account: ")
  262.     newpass = read()
  263.         if newpass == "" then
  264.         print("You can't have a blank password!")
  265.         sleep(2)
  266.         elseif newpass == " " then
  267.         sleep(2)
  268.         print("You can't have a blank password!")
  269.         sleep(2)
  270.         elseif newpass == "password" then
  271.         print("Pick a more secure password!")
  272.         sleep(2)
  273.         elseif newpass == "qwertyuiop" then
  274.         print("Pick a more secure password!")
  275.         sleep(2)
  276.         elseif newpass == "asdfghjkl" then
  277.         print("Pick a more secure password!")
  278.         sleep(2)
  279.         elseif newpass == "zxcvbnm" then
  280.         print("Pick a more secure password!")
  281.         sleep(2)
  282.         else
  283.     break
  284. end
  285. end
  286. print("Password set as '"..newpass.."'.")
  287. passcreate = fs.open("appsupport/passwordlock/users/"..newuser.."/password.txt", "w")
  288. passcreate.writeLine(newpass)
  289. passcreate.close()
  290. fs.makeDir("appsupport/passwordlock/admins/"..newuser)
  291. newuserowner = fs.open("appsupport/passwordlock/admins/"..newuser.."/"..newuser, "w")
  292. newuserowner.writeLine("default")
  293. newuserowner.close()
  294. end
  295.  
  296. signin()
  297. term.setCursorPos(1,6)
  298. print("Signing in...")
  299. -- local username = globaluser / UNCOMMENT LATER!
  300. sleep(2)
  301. cls()
  302. if fs.exists("appsupport/passwordlock/admins/"..globaluser) then
  303. admin = true
  304. end
  305. admintoolsconsole()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement