Guest User

vault

a guest
Nov 8th, 2014
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.24 KB | None | 0 0
  1. side = "left"
  2.  
  3. function save(usr,pass)
  4.   h = fs.open("users/"..usr.."/password","w")
  5.   h.writeLine(pass)
  6.   h.close()
  7. end
  8.  
  9. function check(usr,pass)
  10.   if usr == "changeme" then
  11.     return "admin"
  12.   end
  13.   if not fs.exists("users/"..usr.."/password") then
  14.     return "nousr"
  15.   end
  16.   c = fs.open("users/"..usr.."/password","r")
  17.   if pass == c.readLine() then
  18.     return true
  19.   else
  20.     return false
  21.   end
  22. end
  23.  
  24. while true do
  25.   term.clear()
  26.   term.setCursorPos(1,1)
  27.   term.write("Input Username: ")
  28.   username = read()
  29.   term.setCursorPos(1,2)
  30.   term.write("Input Password: ")
  31.   password = read("*")
  32.     result = check(username,password)
  33.     if result == true then
  34.       redstone.setOutput(side,true)
  35.       sleep(2)
  36.       redstone.setOutput(side,false)
  37.     elseif result == "admin" then
  38.       term.clear()
  39.       term.setCursorPos(1,1)
  40.       term.write("Input new Account username: ")
  41.       newUser = read()
  42.       term.setCursorPos(1,2)
  43.       term.write("Input passowrd for account "..newUser..": ")
  44.       newPass = read("*")
  45.       save(newUser,newPass)
  46.     elseif result == false then
  47.       print("Invalid password")
  48.       sleep(2)
  49.     elseif result == "nousr" then
  50.       print("No such user")
  51.       sleep(2)
  52.     end
  53. end
Advertisement
Add Comment
Please, Sign In to add comment