Advertisement
DOGGYWOOF

test2

Jan 21st, 2024 (edited)
13
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.00 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 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, attemptsLeft)
  22. term.clear()
  23. term.setCursorPos(1, 1)
  24.  
  25. term.setTextColor(colors.cyan)
  26. print("Login to Doggy OS")
  27. print("------------------")
  28.  
  29. term.setTextColor(colors.yellow)
  30. print("Username: " .. username)
  31. print("Attempts left: " .. attemptsLeft)
  32.  
  33. term.setTextColor(colors.white)
  34. print("Enter password:")
  35. end
  36.  
  37. local function checkCredentials(username)
  38. local storedPassword = getUserCredentials(username)
  39.  
  40. if not storedPassword then
  41. return false -- User does not exist
  42. end
  43.  
  44. local attempts = 0
  45.  
  46. repeat
  47. drawLoginScreen(username, MAX_ATTEMPTS - attempts)
  48.  
  49. local enteredPassword = read("*")
  50. attempts = attempts + 1
  51.  
  52. if enteredPassword == storedPassword then
  53. return true
  54. else
  55. term.setTextColor(colors.red)
  56. print("Incorrect password. Please try again.")
  57. os.sleep(2) -- Display the error message for 2 seconds
  58. end
  59. until attempts > MAX_ATTEMPTS
  60.  
  61. term.setTextColor(colors.red)
  62. print("Too many incorrect attempts. Locked out for " .. LOCKOUT_TIME .. " seconds.")
  63. os.sleep(LOCKOUT_TIME)
  64.  
  65. return false
  66. end
  67.  
  68. local function main()
  69. term.clear()
  70. term.setCursorPos(1, 1)
  71.  
  72. term.setTextColor(colors.green)
  73. print("Protected by Doggy OS security")
  74. print("-----------------------------")
  75.  
  76. term.setTextColor(colors.white)
  77. print("Enter username:")
  78.  
  79. local enteredUsername = read()
  80.  
  81. local users = fs.list(USERS_FOLDER)
  82.  
  83. if not users or #users == 0 then
  84. -- No users detected, run the BSOD program
  85. shell.run(ERROR_FOLDER .. BSOD_PROGRAM)
  86. elseif checkCredentials(enteredUsername) then
  87. term.clear()
  88. term.setCursorPos(1, 1)
  89.  
  90. term.setTextColor(colors.lime)
  91. print("Access granted. Welcome, " .. enteredUsername .. "!")
  92. os.sleep(2) -- Display the success message for 2 seconds
  93.  
  94. -- Your main OS code goes here
  95. else
  96. term.clear()
  97. term.setCursorPos(1, 1)
  98.  
  99. term.setTextColor(colors.red)
  100. print("Access denied.")
  101. os.sleep(2) -- Display the access denied message for 2 seconds
  102. end
  103. end
  104.  
  105. main()
  106.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement