Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.loadAPI("hash")
- local userNameText, passwordStarText, plainTextpassword, attempts, attemptsBeforeFailure, cursorIsOn, typingUserName = "", "", "", 0, 3, true, true
- local timerUUID = os.startTimer(0.25)
- local messageToUser = ""
- local messageToUserTicksLeft = 0
- for i,v in pairs(rs.getSides()) do
- if (peripheral.getType(v) == "modem") then
- if (rednet.isOpen(v)) then
- rednet.close(v)
- end
- end
- end -- To be sure nobody is listening
- function checkLogin(userName, password)
- -- passwordHash = hash.hash(password)
- passwordHash = hash.sha256(password)
- if fs.exists("loginPasswords.secure.txt") then
- local passwordFile = fs.open("loginPasswords.secure.txt", "r")
- local passwordTable = textutils.unserialize(passwordFile.readAll()) or {}
- passwordFile.close()
- return passwordTable[userName] == passwordHash
- else
- error("No saved Passwords! Please run \"EditUsers\" and follow its steps.")
- end
- end
- while true do
- term.clear()
- term.setCursorPos(1, 1)
- print("Welcome to computer #", os.getComputerID(), ". Please login.")
- if (cursorIsOn) then
- if (typingUserName) then
- print("Username: ", userNameText, "_")
- print("Password: ", passwordStarText)
- else
- print("Username: ", userNameText)
- print("Password: ", passwordStarText, "_")
- end
- else
- print("Username: ", userNameText)
- print("Password: ", passwordStarText)
- end
- print("\n", messageToUser)
- local event, return1, return2, return3 = os.pullEventRaw()
- if (event == "char") then
- if (typingUserName) then
- userNameText = userNameText .. return1
- else
- passwordStarText = passwordStarText .. "*"
- plainTextpassword = plainTextpassword .. return1
- end
- elseif (event == "key") then
- if (return1 == 28) then
- if (typingUserName) then
- typingUserName = false
- else
- if (checkLogin(userNameText, plainTextpassword)) then
- if (fs.exists("loginStartup")) then
- shell.run("loginStartup")
- return
- end
- else
- attempts = attempts + 1
- if (attempts >= attemptsBeforeFailure) then
- print("Login Failed. Shutting Down.")
- sleep(5)
- os.shutdown()
- else
- messageToUser = "Login Failure #" .. attempts .. "/" .. attemptsBeforeFailure
- messageToUserTicksLeft = 6
- end
- end
- end
- elseif (return1 == 14) then -- delete key
- if (typingUserName) then
- userNameText = string.sub(userNameText, 1, string.len(userNameText) - 1)
- else
- passwordStarText = string.sub(passwordStarText, 1, string.len(passwordStarText) - 1)
- plainTextpassword = string.sub(plainTextpassword, 1, string.len(plainTextpassword) - 1)
- end
- end
- elseif(event == "timer" and timerUUID == return1) then
- if (messageToUserTicksLeft > 0) then
- messageToUserTicksLeft = messageToUserTicksLeft - 1
- if (messageToUserTicksLeft == 0) then
- messageToUser = ""
- end
- end
- cursorIsOn = not cursorIsOn
- timerUUID = os.startTimer(0.25)
- end
- end
- os.unloadAPI("hash")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement