Advertisement
DOGGYWOOF

Untitled

Jan 7th, 2025
10
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.27 KB | None | 0 0
  1. local function checkDiskIDs()
  2. -- Get a list of all connected peripherals
  3. local peripherals = peripheral.getNames()
  4.  
  5. -- Array to store disk IDs
  6. local diskIDs = {}
  7.  
  8. -- Loop through all peripherals
  9. for _, name in ipairs(peripherals) do
  10. -- Check if the peripheral is a disk drive
  11. if peripheral.getType(name) == "drive" then
  12. -- Get the disk ID from the disk drive
  13. local diskID = disk.getID(name)
  14.  
  15. -- If a disk is inserted, add its ID to the array
  16. if diskID then
  17. table.insert(diskIDs, {id = diskID, name = name})
  18. end
  19. end
  20. end
  21.  
  22. -- Check if any disks were found
  23. if #diskIDs > 0 then
  24. return diskIDs
  25. else
  26. return nil
  27. end
  28. end
  29.  
  30. local function drawSecurityCardPrompt()
  31. local contentLines = {
  32. "Please insert your security card.",
  33. "Press ENTER to use password instead."
  34. }
  35. drawPopupWindow("Insert Security Card", contentLines)
  36. end
  37.  
  38. local function drawErrorMessage(message)
  39. drawPopupWindow("Error", {message})
  40. end
  41.  
  42. local function ejectDisk(diskName)
  43. peripheral.call(diskName, "ejectDisk")
  44. end
  45.  
  46. local function insertSecurityCard(username)
  47. local idFolder = fs.combine(USERS_FOLDER .. username, "ID")
  48. if not fs.exists(idFolder) then
  49. return false
  50. end
  51.  
  52. while true do
  53. drawSecurityCardPrompt()
  54.  
  55. local event, key = os.pullEvent()
  56.  
  57. if event == "key" and key == keys.enter then
  58. return false -- Allow password login if enter is pressed
  59. elseif event == "disk" or event == "disk_insert" then
  60. local diskIDs = checkDiskIDs()
  61. if diskIDs then
  62. for _, disk in ipairs(diskIDs) do
  63. ejectDisk(disk.name) -- Eject the disk after checking
  64. local idFile = fs.combine(idFolder, tostring(disk.id) .. ".file")
  65. if fs.exists(idFile) then
  66. return true -- Allow access if a valid security ID is found
  67. end
  68. end
  69. drawErrorMessage("Error: Unregistered security key.")
  70. os.sleep(2)
  71. end
  72. end
  73. end
  74. end
  75.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement