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 storedPassword = file.readLine()
- file.close()
- return storedPassword
- else
- return nil -- User does not exist
- end
- end
- local function drawLoginScreen(username, attemptsLeft)
- term.clear()
- term.setCursorPos(1, 1)
- term.setTextColor(colors.cyan)
- print("Login to Doggy OS")
- print("------------------")
- term.setTextColor(colors.yellow)
- print("Username: " .. username)
- print("Attempts left: " .. attemptsLeft)
- term.setTextColor(colors.white)
- print("Enter password:")
- 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)
- local enteredPassword = read("*")
- attempts = attempts + 1
- if enteredPassword == storedPassword then
- return true
- else
- term.setTextColor(colors.red)
- print("Incorrect password. Please try again.")
- os.sleep(2) -- Display the error message for 2 seconds
- end
- until attempts > MAX_ATTEMPTS
- term.setTextColor(colors.red)
- print("Too many incorrect attempts. Locked out for " .. LOCKOUT_TIME .. " seconds.")
- os.sleep(LOCKOUT_TIME)
- return false
- end
- local function main()
- term.clear()
- term.setCursorPos(1, 1)
- term.setTextColor(colors.green)
- print("Protected by Doggy OS security")
- print("-----------------------------")
- term.setTextColor(colors.white)
- 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
- term.clear()
- term.setCursorPos(1, 1)
- term.setTextColor(colors.lime)
- print("Access granted. Welcome, " .. enteredUsername .. "!")
- os.sleep(2) -- Display the success message for 2 seconds
- -- Your main OS code goes here
- else
- term.clear()
- term.setCursorPos(1, 1)
- term.setTextColor(colors.red)
- print("Access denied.")
- os.sleep(2) -- Display the access denied message for 2 seconds
- end
- end
- main()
Add Comment
Please, Sign In to add comment