Advertisement
DOGGYWOOF

Untitled

Jan 24th, 2025
12
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.24 KB | None | 0 0
  1. -- Constants for security configuration
  2. local MAX_ATTEMPTS = 3 -- Maximum number of incorrect password attempts allowed
  3. local LOCKOUT_TIME = 30 -- Lockout time in seconds after reaching maximum attempts
  4.  
  5. local USERS_FOLDER = "/disk/users/"
  6. local ERROR_FOLDER = "/disk/error/"
  7. local BSOD_PROGRAM = "BSOD.lua"
  8. local CURRENT_USER_FILE = ".currentusr"
  9. local SHOW_ALL_USERS_FILE = "/disk/config/security/login/ShowAllUsers.cfg"
  10.  
  11. -- Utility function to draw a centered popup window with a text-based border
  12. local function drawPopupWindow(headerText, contentLines, windowWidth, windowHeight)
  13. term.clear()
  14. local w, h = term.getSize()
  15.  
  16. -- Determine dimensions of the popup
  17. local maxLength = #headerText
  18. for _, line in ipairs(contentLines) do
  19. maxLength = math.max(maxLength, #line)
  20. end
  21. windowWidth = windowWidth or (maxLength + 4)
  22. windowHeight = windowHeight or (#contentLines + 4)
  23.  
  24. local xStart = math.floor(w / 2 - windowWidth / 2)
  25. local yStart = math.floor(h / 2 - windowHeight / 2)
  26.  
  27. -- Draw border with animation
  28. term.setCursorPos(xStart, yStart)
  29. term.write("+" .. string.rep("-", windowWidth - 2) .. "+")
  30. for i = 1, windowHeight - 2 do
  31. term.setCursorPos(xStart, yStart + i)
  32. term.write("|" .. string.rep(" ", windowWidth - 2) .. "|")
  33. os.sleep(0.05)
  34. end
  35. term.setCursorPos(xStart, yStart + windowHeight - 1)
  36. term.write("+" .. string.rep("-", windowWidth - 2) .. "+")
  37.  
  38. -- Draw header
  39. term.setCursorPos(xStart + 2, yStart + 1)
  40. term.write(headerText)
  41.  
  42. -- Draw content
  43. for i, line in ipairs(contentLines) do
  44. term.setCursorPos(xStart + 2, yStart + 1 + i + 1)
  45. term.write(line)
  46. os.sleep(0.05)
  47. end
  48. end
  49.  
  50. -- Function to reset the password
  51. local function resetPassword(username)
  52. -- Check for recovery methods: security card or recovery key
  53. local idFolder = fs.combine(USERS_FOLDER .. username, "ID")
  54. local recoveryKeyFile = fs.combine(USERS_FOLDER .. username, "rckey.txt")
  55. local resetMethod = nil
  56.  
  57. -- Prompt for reset method
  58. drawPopupWindow("Password Reset Options", {
  59. "Choose one of the following methods:",
  60. "1. Insert a valid security card.",
  61. "2. Enter your recovery key."
  62. })
  63.  
  64. while true do
  65. local event, key = os.pullEvent("key")
  66. if key == keys.one then
  67. resetMethod = "card"
  68. break
  69. elseif key == keys.two then
  70. resetMethod = "key"
  71. break
  72. end
  73. end
  74.  
  75. if resetMethod == "card" then
  76. -- Attempt security card verification
  77. while true do
  78. drawPopupWindow("Insert Security Card", {"Insert a valid security card to reset your password."})
  79. local event = os.pullEvent()
  80. if event == "disk" or event == "disk_insert" then
  81. local diskIDs = checkDiskIDs()
  82. if diskIDs then
  83. for _, disk in ipairs(diskIDs) do
  84. ejectDisk(disk.name)
  85. local idFile = fs.combine(idFolder, tostring(disk.id) .. ".file")
  86. if fs.exists(idFile) then
  87. drawPopupWindow("Card Verified", {"Security card accepted!"})
  88. os.sleep(2)
  89. goto setNewPassword
  90. end
  91. end
  92. end
  93. drawPopupWindow("Invalid Card", {"The security card is not valid."})
  94. os.sleep(2)
  95. end
  96. end
  97. elseif resetMethod == "key" then
  98. -- Attempt recovery key verification
  99. if not fs.exists(recoveryKeyFile) then
  100. drawPopupWindow("Error", {"No recovery key file found for this user."})
  101. os.sleep(2)
  102. return
  103. end
  104.  
  105. local file = fs.open(recoveryKeyFile, "r")
  106. local storedRecoveryKey = file.readLine()
  107. file.close()
  108.  
  109. drawPopupWindow("Recovery Key Verification", {"Enter your recovery key:"})
  110. term.setCursorPos(1, select(2, term.getSize()))
  111. term.write(":")
  112. local enteredKey = read("*")
  113.  
  114. if enteredKey ~= storedRecoveryKey then
  115. drawPopupWindow("Invalid Recovery Key", {"The recovery key you entered is incorrect."})
  116. os.sleep(2)
  117. return
  118. end
  119.  
  120. drawPopupWindow("Recovery Key Verified", {"Recovery key accepted!"})
  121. os.sleep(2)
  122. end
  123.  
  124. ::setNewPassword::
  125. -- Set a new password for the user
  126. drawPopupWindow("Set New Password", {"Enter a new password for user: " .. username})
  127. term.setCursorPos(1, select(2, term.getSize()))
  128. term.write(":")
  129. local newPassword = read("*")
  130.  
  131. -- Save the new password
  132. local passwordFile = fs.combine(USERS_FOLDER .. username, "password.txt")
  133. local file = fs.open(passwordFile, "w")
  134. file.write(newPassword)
  135. file.close()
  136.  
  137. drawPopupWindow("Password Reset", {"Password has been successfully reset!"})
  138. os.sleep(2)
  139.  
  140. -- Automatically log in the user after resetting the password
  141. saveCurrentUser(username)
  142. shell.run("/disk/os/gui")
  143. end
  144.  
  145. -- Other functions remain unchanged, except for integrating resetPassword into the flow
  146.  
  147. -- Main function for login process
  148. local function main()
  149. term.setTextColor(colors.white)
  150. term.setBackgroundColor(colors.black)
  151. term.clear()
  152.  
  153. local username
  154.  
  155. if fs.exists(SHOW_ALL_USERS_FILE) then
  156. username = selectUserFromList()
  157. else
  158. drawPopupWindow("Protected by Doggy OS Security", {"Enter username:"})
  159. username = read()
  160. end
  161.  
  162. -- Attempt security card login first
  163. if insertSecurityCard(username) then
  164. drawPopupWindow("Access Granted", {"Security card verified. Welcome, " .. username .. "!"})
  165. os.sleep(2)
  166. saveCurrentUser(username)
  167. shell.run("/disk/os/gui")
  168. return
  169. end
  170.  
  171. -- Fallback to password login if card verification fails or is bypassed
  172. if checkCredentials(username) then
  173. drawPopupWindow("Access Granted", {"Welcome, " .. username .. "!"})
  174. os.sleep(2)
  175. shell.run("/disk/os/gui")
  176. else
  177. shell.run("/disk/os/lock.lua")
  178. end
  179. end
  180.  
  181. main()
  182.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement