Advertisement
DOGGYWOOF

Untitled

Jan 24th, 2025 (edited)
12
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.23 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. drawPopupWindow("Password Reset", {"Select a recovery method:"})
  53. print("1. Insert a valid security card")
  54. print("2. Enter a recovery key")
  55. write("Option: ")
  56. local choice = read()
  57.  
  58. if choice == "1" then
  59. -- Security card method
  60. if insertSecurityCard(username) then
  61. drawPopupWindow("Password Reset", {"Security card verified."})
  62. else
  63. drawPopupWindow("Password Reset Failed", {"Invalid or missing security card."})
  64. return
  65. end
  66. elseif choice == "2" then
  67. -- Recovery key method
  68. local recoveryKeyPath = fs.combine(USERS_FOLDER .. username, "rckey.txt")
  69. if not fs.exists(recoveryKeyPath) then
  70. drawPopupWindow("Password Reset Failed", {"Recovery key not found."})
  71. return
  72. end
  73.  
  74. drawPopupWindow("Password Reset", {"Enter your recovery key:"})
  75. write("Recovery Key: ")
  76. local enteredKey = read("*")
  77. local file = fs.open(recoveryKeyPath, "r")
  78. local storedKey = file.readLine()
  79. file.close()
  80.  
  81. if enteredKey ~= storedKey then
  82. drawPopupWindow("Password Reset Failed", {"Incorrect recovery key."})
  83. return
  84. end
  85. else
  86. drawPopupWindow("Password Reset Failed", {"Invalid option selected."})
  87. return
  88. end
  89.  
  90. -- Request new password
  91. drawPopupWindow("Password Reset", {"Enter your new password:"})
  92. write("New Password: ")
  93. local newPassword = read("*")
  94. write("Confirm Password: ")
  95. local confirmPassword = read("*")
  96.  
  97. if newPassword ~= confirmPassword then
  98. drawPopupWindow("Password Reset Failed", {"Passwords do not match."})
  99. return
  100. end
  101.  
  102. -- Update the password
  103. local passwordFile = fs.combine(USERS_FOLDER .. username, "password.txt")
  104. local file = fs.open(passwordFile, "w")
  105. file.write(newPassword)
  106. file.close()
  107.  
  108. drawPopupWindow("Password Reset Successful", {"Your password has been updated."})
  109. os.sleep(2)
  110. saveCurrentUser(username)
  111. shell.run("/disk/os/gui")
  112. end
  113.  
  114. -- Function to list all users
  115. local function listUsers()
  116. local users = fs.list(USERS_FOLDER)
  117. local usernames = {}
  118. for _, user in ipairs(users) do
  119. local userDir = fs.combine(USERS_FOLDER, user)
  120. if fs.isDir(userDir) then
  121. table.insert(usernames, user)
  122. end
  123. end
  124. return usernames
  125. end
  126.  
  127. -- Function to save the current user
  128. local function saveCurrentUser(username)
  129. if fs.exists(CURRENT_USER_FILE) then
  130. fs.delete(CURRENT_USER_FILE)
  131. end
  132. local file = fs.open(CURRENT_USER_FILE, "w")
  133. file.write(username)
  134. file.close()
  135. end
  136.  
  137. -- Function to handle security card login
  138. local function insertSecurityCard(username)
  139. local idFolder = fs.combine(USERS_FOLDER .. username, "ID")
  140. if not fs.exists(idFolder) then
  141. return false
  142. end
  143.  
  144. while true do
  145. drawPopupWindow("Doggy OS Security", {"Insert a valid security card to login or reset password.", "Press ENTER to exit."})
  146.  
  147. local event, key = os.pullEvent()
  148.  
  149. if event == "key" and key == keys.enter then
  150. return false
  151. elseif event == "disk" or event == "disk_insert" then
  152. local peripherals = peripheral.getNames()
  153. for _, name in ipairs(peripherals) do
  154. if peripheral.getType(name) == "drive" then
  155. local diskID = disk.getID(name)
  156. if diskID then
  157. local idFile = fs.combine(idFolder, tostring(diskID) .. ".file")
  158. if fs.exists(idFile) then
  159. return true
  160. end
  161. end
  162. end
  163. end
  164. drawPopupWindow("Security Check", {"Invalid security card."})
  165. os.sleep(2)
  166. end
  167. end
  168. end
  169.  
  170. -- Main function
  171. local function main()
  172. term.setTextColor(colors.white)
  173. term.setBackgroundColor(colors.black)
  174. term.clear()
  175.  
  176. drawPopupWindow("Doggy OS Login", {"Enter username:"})
  177. local username = read()
  178.  
  179. drawPopupWindow("Doggy OS Login", {"Enter your password or type @reset to reset password."})
  180. local enteredPassword = read("*")
  181.  
  182. if enteredPassword == "@reset" then
  183. resetPassword(username)
  184. else
  185. -- Add your login logic here
  186. end
  187. end
  188.  
  189. main()
  190.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement