Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local MAX_ATTEMPTS = 3 -- Maximum number of incorrect password attempts allowed
- local LOCKOUT_TIME = 30 -- Lockout time in seconds after reaching the maximum attempts
- local USERS_FOLDER = "/disk/users/"
- local ERROR_FOLDER = "/disk/error/"
- local BSOD_PROGRAM = "BSOD.lua"
- local function getUserCredentials(username)
- local passwordFile = fs.combine(USERS_FOLDER .. username, "password.txt")
- if fs.exists(passwordFile) then
- local file = fs.open(passwordFile, "r")
- local storedPassword = file.readLine()
- file.close()
- return storedPassword
- else
- return nil -- User does not exist
- end
- end
- local function drawLoginScreen(username, password, attemptsLeft)
- term.clear()
- term.setCursorPos(1, 1)
- print("Username: " .. username)
- print("Password: " .. string.rep("*", #password))
- print("Attempts left: " .. tostring(attemptsLeft))
- end
- local function checkCredentials(username)
- local storedPassword = getUserCredentials(username)
- if not storedPassword then
- return false -- User does not exist
- end
- local attempts = 0
- repeat
- drawLoginScreen(username, "", MAX_ATTEMPTS - attempts)
- term.setCursorPos(12, 2)
- write("Enter password:")
- local enteredPassword = read("*")
- attempts = attempts + 1
- if enteredPassword == storedPassword then
- return true
- else
- print("Incorrect password.")
- sleep(1)
- end
- until attempts >= MAX_ATTEMPTS
- print("Too many incorrect attempts. Locked out for " .. LOCKOUT_TIME .. " seconds.")
- sleep(LOCKOUT_TIME)
- return false
- end
- local function main()
- term.clear()
- term.setCursorPos(1, 1)
- print("Enter username:")
- local enteredUsername = read()
- local users = fs.list(USERS_FOLDER)
- if not users or #users == 0 then
- -- No users detected, run the BSOD program
- shell.run(ERROR_FOLDER .. BSOD_PROGRAM)
- elseif checkCredentials(enteredUsername) then
- print("Access granted. Welcome, " .. enteredUsername .. "!")
- -- Your main OS code goes here
- else
- print("Access denied.")
- end
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement