Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function checkDiskIDs()
- -- Get a list of all connected peripherals
- local peripherals = peripheral.getNames()
- -- Array to store disk IDs
- local diskIDs = {}
- -- Loop through all peripherals
- for _, name in ipairs(peripherals) do
- -- Check if the peripheral is a disk drive
- if peripheral.getType(name) == "drive" then
- -- Get the disk ID from the disk drive
- local diskID = disk.getID(name)
- -- If a disk is inserted, add its ID to the array
- if diskID then
- table.insert(diskIDs, {id = diskID, name = name})
- end
- end
- end
- -- Check if any disks were found
- if #diskIDs > 0 then
- return diskIDs
- else
- return nil
- end
- end
- local function drawSecurityCardPrompt()
- local contentLines = {
- "Please insert your security card.",
- "Press ENTER to use password instead."
- }
- drawPopupWindow("Insert Security Card", contentLines)
- end
- local function drawErrorMessage(message)
- drawPopupWindow("Error", {message})
- end
- local function ejectDisk(diskName)
- peripheral.call(diskName, "ejectDisk")
- end
- local function insertSecurityCard(username)
- local idFolder = fs.combine(USERS_FOLDER .. username, "ID")
- if not fs.exists(idFolder) then
- return false
- end
- while true do
- drawSecurityCardPrompt()
- local event, key = os.pullEvent()
- if event == "key" and key == keys.enter then
- return false -- Allow password login if enter is pressed
- elseif event == "disk" or event == "disk_insert" then
- local diskIDs = checkDiskIDs()
- if diskIDs then
- for _, disk in ipairs(diskIDs) do
- ejectDisk(disk.name) -- Eject the disk after checking
- local idFile = fs.combine(idFolder, tostring(disk.id) .. ".file")
- if fs.exists(idFile) then
- return true -- Allow access if a valid security ID is found
- end
- end
- drawErrorMessage("Error: Unregistered security key.")
- os.sleep(2)
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement