randomdude999

SecuritySystem: ChangePass

Jul 24th, 2015
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.45 KB | None | 0 0
  1. os.loadAPI("/.apis/sha")
  2. local w,h = term.getSize()
  3. function getPass()
  4.   local inTerm = window.create(term.current(),w/2-6,h/2,13,1,true)
  5.   local oldTerm = term.redirect(inTerm)
  6.   term.setBackgroundColor(2^7)
  7.   term.write("            ")
  8.   term.setCursorPos(1,1)
  9.   local out = read("*")
  10.   term.redirect(oldTerm)
  11.   term.clear()
  12.   term.setCursorPos(1,1)
  13.   return out
  14. end
  15. local passHashHandle = fs.open("/SecuritySystem/.passhash","r")
  16. local passHash = passHashHandle.readAll()
  17. passHashHandle.close()
  18. while true do
  19.   term.clear()
  20.   term.setCursorPos(math.ceil((w-17)/2),h/2-2)
  21.   term.write("Current Password:")
  22.   local input = getPass()
  23.   if sha.sha256(input)==passHash then
  24.     term.clear()
  25.     term.setCursorPos(math.ceil((w-13)/2),h/2-2)
  26.     term.write("New Password:")
  27.     local newpass = getPass()
  28.     term.setCursorPos(math.ceil((w-16)/2),h/2-2)
  29.     term.write("Repeat Password:")
  30.     local input = getPass()
  31.     if newpass == input then
  32.       local file = fs.open("/SecuritySystem/.passhash","w")
  33.       file.write(sha.sha256(newpass))
  34.       file.close()
  35.       term.setCursorPos(math.ceil((w-16)/2),h/2)
  36.       term.write("Password changed")
  37.       sleep(2)
  38.       break
  39.     else
  40.       term.setCursorPos(math.ceil((w-21)/2),h/2)
  41.       term.write("Passwords don't match")
  42.       sleep(2)
  43.     end
  44.   else
  45.     term.setCursorPos(math.ceil((w-8)/2),h/2)
  46.     term.write("Incorrect!")
  47.     sleep(2)
  48.   end
  49. end
  50. term.clear()
  51. term.setCursorPos(1,1)
Advertisement
Add Comment
Please, Sign In to add comment