Advertisement
DOGGYWOOF

test

Jan 21st, 2024
10
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.28 KB | None | 0 0
  1. local MAX_ATTEMPTS = 3 -- Maximum number of incorrect password attempts allowed
  2. local LOCKOUT_TIME = 30 -- Lockout time in seconds after reaching the maximum attempts
  3.  
  4. local USERS_FOLDER = "/disk/users/"
  5. local ERROR_FOLDER = "/disk/error/"
  6. local BSOD_PROGRAM = "BSOD.lua"
  7.  
  8. local function getUserCredentials(username)
  9. local passwordFile = fs.combine(USERS_FOLDER .. username, "password.txt")
  10.  
  11. if fs.exists(passwordFile) then
  12. local file = fs.open(passwordFile, "r")
  13. local storedPassword = file.readLine()
  14. file.close()
  15. return storedPassword
  16. else
  17. return nil -- User does not exist
  18. end
  19. end
  20.  
  21. local function drawLoginScreen(username, password, attemptsLeft)
  22. term.clear()
  23. term.setCursorPos(1, 1)
  24.  
  25. print("Username: " .. username)
  26. print("Password: " .. string.rep("*", #password))
  27. print("Attempts left: " .. tostring(attemptsLeft))
  28. end
  29.  
  30. local function checkCredentials(username)
  31. local storedPassword = getUserCredentials(username)
  32.  
  33. if not storedPassword then
  34. return false -- User does not exist
  35. end
  36.  
  37. local attempts = 0
  38.  
  39. repeat
  40. drawLoginScreen(username, "", MAX_ATTEMPTS - attempts)
  41.  
  42. term.setCursorPos(12, 2)
  43. write("Enter password:")
  44. local enteredPassword = read("*")
  45. attempts = attempts + 1
  46.  
  47. if enteredPassword == storedPassword then
  48. return true
  49. else
  50. print("Incorrect password.")
  51. sleep(1)
  52. end
  53. until attempts >= MAX_ATTEMPTS
  54.  
  55. print("Too many incorrect attempts. Locked out for " .. LOCKOUT_TIME .. " seconds.")
  56. sleep(LOCKOUT_TIME)
  57.  
  58. return false
  59. end
  60.  
  61. local function main()
  62. term.clear()
  63. term.setCursorPos(1, 1)
  64.  
  65. print("Enter username:")
  66. local enteredUsername = read()
  67.  
  68. local users = fs.list(USERS_FOLDER)
  69.  
  70. if not users or #users == 0 then
  71. -- No users detected, run the BSOD program
  72. shell.run(ERROR_FOLDER .. BSOD_PROGRAM)
  73. elseif checkCredentials(enteredUsername) then
  74. print("Access granted. Welcome, " .. enteredUsername .. "!")
  75. -- Your main OS code goes here
  76. else
  77. print("Access denied.")
  78. end
  79. end
  80.  
  81. main()
  82.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement