Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require("/scripts/auth/sha256")
- local oldPull = os.pullEvent
- os.pullEvent = os.pullEventRaw
- function resetCursor(x, y)
- term.clear()
- term.setCursorPos(x, y)
- end
- function verify_user(username, password)
- for line in io.lines("/.password") do
- i = string.find(line, "|")
- if (i ~= nil and string.sub(line, 1, i-1) == username) then
- digest = digestStr(password)
- if string.sub(line, i+1) == digest then
- resetCursor(1, 1)
- print("Welcome back!")
- return true
- else
- resetCursor(1, 1)
- print("Wrong password")
- return false
- end
- end
- end
- resetCursor(1, 1)
- print("User '"..username.."' does not exist")
- return false
- end
- local auth = false
- resetCursor(1, 1)
- while not auth do
- io.write("Username: ")
- local username = string.gsub(read(), "^ +", "")
- username = string.gsub(username, " +$", "")
- io.write("Password: ")
- local password = read("*")
- auth = verify_user(username, password)
- if not auth then
- sleep(2)
- resetCursor(1, 1)
- end
- end
- os.pullEvent = oldPull
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement