Advertisement
DOGGYWOOF

Enterprise blocker

Jan 20th, 2024 (edited)
10
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 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 maximum attempts
  3.  
  4. local USERS_FOLDER = "/disk/users/"
  5. local ERROR_FOLDER = "/disk/error/"
  6. local OS_GUI_PROGRAM = "/disk/os/gui"
  7. local NOT_ADMIN_MESSAGE = "This user is not an admin."
  8.  
  9. local function getUserCredentials(username)
  10. local passwordFile = fs.combine(USERS_FOLDER .. username, "password.txt")
  11.  
  12. if fs.exists(passwordFile) then
  13. local file = fs.open(passwordFile, "r")
  14. local storedPassword = file.readLine()
  15. file.close()
  16. return storedPassword
  17. else
  18. return nil -- User does not exist
  19. end
  20. end
  21.  
  22. local function getAdminCredentials()
  23. local adminFile = "/disk/admin.txt"
  24.  
  25. if fs.exists(adminFile) then
  26. local file = fs.open(adminFile, "r")
  27. local storedPassword = file.readLine()
  28. file.close()
  29. return storedPassword
  30. else
  31. return nil -- Admin file does not exist
  32. end
  33. end
  34.  
  35. local function checkCredentials(username)
  36. if username == "admin" then
  37. local storedPassword = getAdminCredentials()
  38.  
  39. if not storedPassword then
  40. return false -- Admin credentials not set
  41. end
  42.  
  43. local attempts = 0
  44.  
  45. repeat
  46. term.clear()
  47. term.setCursorPos(1, 1)
  48. print("Enter password for " .. username .. ":")
  49. local enteredPassword = read("*")
  50. attempts = attempts + 1
  51.  
  52. if enteredPassword == storedPassword then
  53. return true
  54. else
  55. print("Incorrect password. Attempts left: " .. tostring(MAX_ATTEMPTS - attempts))
  56. end
  57. until attempts >= MAX_ATTEMPTS
  58.  
  59. print("Too many incorrect attempts. Locked out for " .. LOCKOUT_TIME .. " seconds.")
  60. os.sleep(LOCKOUT_TIME)
  61. return false
  62. else
  63. -- Non-admin users are not allowed to log in
  64. print(NOT_ADMIN_MESSAGE)
  65. return false
  66. end
  67. end
  68.  
  69. local function main()
  70. term.clear()
  71. term.setCursorPos(1, 1)
  72.  
  73. print("Enter username:")
  74. local enteredUsername = read()
  75.  
  76. if checkCredentials(enteredUsername) then
  77. print("Access granted. Welcome, " .. enteredUsername .. "!")
  78. shell.run(OS_GUI_PROGRAM) -- Run the OS GUI after successful login
  79. end
  80. end
  81.  
  82. main()
  83.  
  84.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement