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 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 password = file.readLine()
- file.close()
- return password
- else
- return nil -- User does not exist
- end
- end
- local function setUserCredentials(username, password)
- local userFolder = fs.combine(USERS_FOLDER, username)
- fs.makeDir(userFolder)
- local passwordFile = fs.combine(userFolder, "password.txt")
- local file = fs.open(passwordFile, "w")
- file.writeLine(password)
- file.close()
- end
- local function checkCredentials(username)
- local storedPassword = getUserCredentials(username)
- if not storedPassword then
- return false -- User does not exist
- end
- local attempts = 0
- repeat
- term.clear()
- term.setCursorPos(1, 1)
- print("Enter password for " .. username .. ":")
- local enteredPassword = read("*")
- attempts = attempts + 1
- if enteredPassword == storedPassword then
- return true
- else
- print("Incorrect password. Attempts left: " .. tostring(MAX_ATTEMPTS - attempts))
- end
- until attempts >= MAX_ATTEMPTS
- print("Too many incorrect attempts. Locked out for " .. LOCKOUT_TIME .. " seconds.")
- os.sleep(LOCKOUT_TIME)
- return false
- end
- local function main()
- 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)
- else
- term.clear()
- term.setCursorPos(1, 1)
- print("Enter username:")
- local enteredUsername = read()
- if checkCredentials(enteredUsername) then
- print("Access granted. Welcome, " .. enteredUsername .. "!")
- -- Your main OS code goes here
- else
- print("Access denied.")
- end
- end
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement