Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local MAX_ATTEMPTS = 3 -- Maximum 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("Doggy OS Login")
- print("--------------")
- term.setTextColor(colors.yellow)
- print("User: " .. username)
- print("Attempts Left: " .. attemptsLeft)
- term.setTextColor(colors.white)
- print("Enter Password:")
- end
- local function lockoutUser(username)
- local disabledFile = fs.combine(USERS_FOLDER .. username, "disabled.txt")
- local file = fs.open(disabledFile, "w")
- file.close()
- end
- local function checkDisabled(username)
- local disabledFile = fs.combine(USERS_FOLDER .. username, "disabled.txt")
- return fs.exists(disabledFile)
- end
- local function checkCredentials(username)
- if checkDisabled(username) then
- term.clear()
- term.setCursorPos(1, 1)
- term.setTextColor(colors.red)
- print("This user has been disabled for security reasons.")
- os.sleep(3) -- Display the disabled message for 3 seconds
- print("Contact your administrator for assistance.")
- os.sleep(2) -- Display the contact administrator message for 2 seconds
- shell.run("/disk/os/lock.lua") -- Run the lock.lua program
- return false
- end
- 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
- print("Too many incorrect attempts. User has been disabled.")
- lockoutUser(username)
- os.sleep(2) -- Display the lockout message for 2 seconds
- return false
- end
- local function getUserList()
- local users = fs.list(USERS_FOLDER)
- local validUsers = {}
- for _, user in ipairs(users) do
- local blockFile = fs.combine(USERS_FOLDER .. user, "block.txt")
- if not fs.exists(blockFile) then
- table.insert(validUsers, user)
- end
- end
- return validUsers
- end
- local function displayUserMenu()
- term.clear()
- term.setCursorPos(1, 1)
- term.setTextColor(colors.green)
- print("Welcome to Doggy OS")
- print("--------------------")
- print("Select a user to log in:\n")
- local userList = getUserList()
- for i, user in ipairs(userList) do
- print(i .. ". " .. user)
- end
- term.setTextColor(colors.white)
- write("\nEnter the number corresponding to the user: ")
- local choice = tonumber(read())
- if choice and userList[choice] then
- return userList[choice]
- else
- return nil
- end
- end
- local function main()
- term.clear()
- term.setCursorPos(1, 1)
- term.setTextColor(colors.green)
- print("Secured by Doggy OS")
- print("--------------------")
- local enteredUsername = displayUserMenu()
- if not enteredUsername then
- term.clear()
- term.setCursorPos(1, 1)
- term.setTextColor(colors.red)
- print("Invalid user selection.")
- os.sleep(2) -- Display the invalid selection message for 2 seconds
- return
- end
- if checkDisabled(enteredUsername) then
- term.clear()
- term.setCursorPos(1, 1)
- term.setTextColor(colors.red)
- print("This user is temporarily disabled for security reasons.")
- os.sleep(3) -- Display the disabled message for 3 seconds
- print("Contact your administrator for assistance.")
- os.sleep(2) -- Display the contact administrator message for 2 seconds
- shell.run("/disk/os/lock.lua") -- Run the lock.lua program
- return
- end
- if not checkCredentials(enteredUsername) then
- term.clear()
- term.setCursorPos(1, 1)
- term.setTextColor(colors.red)
- print("Access denied.")
- os.sleep(2) -- Display the access denied message for 2 seconds
- return
- end
- 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
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement