Advertisement
DOGGYWOOF

choose user

Feb 3rd, 2024 (edited)
18
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.27 KB | None | 0 0
  1. local MAX_ATTEMPTS = 3 -- Maximum 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("Doggy OS Login")
  27. print("--------------")
  28.  
  29. term.setTextColor(colors.yellow)
  30. print("User: " .. username)
  31. print("Attempts Left: " .. attemptsLeft)
  32.  
  33. term.setTextColor(colors.white)
  34. print("Enter Password:")
  35. end
  36.  
  37. local function lockoutUser(username)
  38. local disabledFile = fs.combine(USERS_FOLDER .. username, "disabled.txt")
  39. local file = fs.open(disabledFile, "w")
  40. file.close()
  41. end
  42.  
  43. local function checkDisabled(username)
  44. local disabledFile = fs.combine(USERS_FOLDER .. username, "disabled.txt")
  45. return fs.exists(disabledFile)
  46. end
  47.  
  48. local function checkCredentials(username)
  49. if checkDisabled(username) then
  50. term.clear()
  51. term.setCursorPos(1, 1)
  52. term.setTextColor(colors.red)
  53. print("This user has been disabled for security reasons.")
  54. os.sleep(3) -- Display the disabled message for 3 seconds
  55. print("Contact your administrator for assistance.")
  56. os.sleep(2) -- Display the contact administrator message for 2 seconds
  57. shell.run("/disk/os/lock.lua") -- Run the lock.lua program
  58. return false
  59. end
  60.  
  61. local storedPassword = getUserCredentials(username)
  62.  
  63. if not storedPassword then
  64. return false -- User does not exist
  65. end
  66.  
  67. local attempts = 0
  68.  
  69. repeat
  70. drawLoginScreen(username, MAX_ATTEMPTS - attempts)
  71.  
  72. local enteredPassword = read("*")
  73. attempts = attempts + 1
  74.  
  75. if enteredPassword == storedPassword then
  76. return true
  77. else
  78. term.setTextColor(colors.red)
  79. print("Incorrect password. Please try again.")
  80. os.sleep(2) -- Display the error message for 2 seconds
  81. end
  82. until attempts > MAX_ATTEMPTS
  83.  
  84. print("Too many incorrect attempts. User has been disabled.")
  85. lockoutUser(username)
  86. os.sleep(2) -- Display the lockout message for 2 seconds
  87.  
  88. return false
  89. end
  90.  
  91. local function getUserList()
  92. local users = fs.list(USERS_FOLDER)
  93. local validUsers = {}
  94.  
  95. for _, user in ipairs(users) do
  96. local blockFile = fs.combine(USERS_FOLDER .. user, "block.txt")
  97. if not fs.exists(blockFile) then
  98. table.insert(validUsers, user)
  99. end
  100. end
  101.  
  102. return validUsers
  103. end
  104.  
  105. local function displayUserMenu()
  106. term.clear()
  107. term.setCursorPos(1, 1)
  108.  
  109. term.setTextColor(colors.green)
  110. print("Welcome to Doggy OS")
  111. print("--------------------")
  112.  
  113. print("Select a user to log in:\n")
  114.  
  115. local userList = getUserList()
  116.  
  117. for i, user in ipairs(userList) do
  118. print(i .. ". " .. user)
  119. end
  120.  
  121. term.setTextColor(colors.white)
  122. write("\nEnter the number corresponding to the user: ")
  123. local choice = tonumber(read())
  124.  
  125. if choice and userList[choice] then
  126. return userList[choice]
  127. else
  128. return nil
  129. end
  130. end
  131.  
  132. local function main()
  133. term.clear()
  134. term.setCursorPos(1, 1)
  135.  
  136. term.setTextColor(colors.green)
  137. print("Secured by Doggy OS")
  138. print("--------------------")
  139.  
  140. local enteredUsername = displayUserMenu()
  141.  
  142. if not enteredUsername then
  143. term.clear()
  144. term.setCursorPos(1, 1)
  145.  
  146. term.setTextColor(colors.red)
  147. print("Invalid user selection.")
  148. os.sleep(2) -- Display the invalid selection message for 2 seconds
  149. return
  150. end
  151.  
  152. if checkDisabled(enteredUsername) then
  153. term.clear()
  154. term.setCursorPos(1, 1)
  155. term.setTextColor(colors.red)
  156. print("This user is temporarily disabled for security reasons.")
  157. os.sleep(3) -- Display the disabled message for 3 seconds
  158. print("Contact your administrator for assistance.")
  159. os.sleep(2) -- Display the contact administrator message for 2 seconds
  160. shell.run("/disk/os/lock.lua") -- Run the lock.lua program
  161. return
  162. end
  163.  
  164. if not checkCredentials(enteredUsername) then
  165. term.clear()
  166. term.setCursorPos(1, 1)
  167.  
  168. term.setTextColor(colors.red)
  169. print("Access denied.")
  170. os.sleep(2) -- Display the access denied message for 2 seconds
  171. return
  172. end
  173.  
  174. term.clear()
  175. term.setCursorPos(1, 1)
  176.  
  177. term.setTextColor(colors.lime)
  178. print("Access granted. Welcome, " .. enteredUsername .. "!")
  179. os.sleep(2) -- Display the success message for 2 seconds
  180.  
  181. -- Your main OS code goes here
  182. end
  183.  
  184. main()
  185.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement