Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- term.clear()
- term.setCursorPos(1, 1)
- termX, termY = term.getSize()
- if not fs.isDir('.PasswordFiles') then
- if fs.exists('.PasswordFiles') then
- fs.delete('.PasswordFiles')
- end
- fs.makeDir('.PasswordFiles')
- end
- if not fs.exists(".PasswordFiles/Password") then
- print("Password file not found. Access granted")
- else
- passFile = fs.open(".PasswordFiles/Password", "r")
- pass = passFile.readLine()
- passFile.close()
- term.write("You have _ attempts to enter correct password")
- function accessCodeMatch(diskACfile)
- equal = true
- if not fs.exists(".PasswordFiles/AccessCode") then return false
- else
- pcACfile = fs.open(".PasswordFiles/AccessCode", "rb")
- for n = 1, 32 do
- pcByte = pcACfile.read()
- diskByte = diskACfile.read()
- if pcByte ~= diskByte then
- equal = false
- break
- end
- end
- pcACfile.close()
- return equal
- end
- end
- function checkDrive(sSide)
- if sSide == "all" then
- return checkDrive("bottom") or checkDrive("top") or checkDrive("left") or checkDrive("right") or checkDrive("front") or checkDrive("back")
- else if (sSide == "bottom") or (sSide == "top") or (sSide == "left") or (sSide == "right") or (sSide == "front") or (sSide == "back") then
- if disk.isPresent(sSide) then
- if disk.hasData(sSide) then
- if fs.exists(disk.getMountPath(sSide) .. "/AccessCode") then
- accessCodeFile = fs.open(disk.getMountPath(sSide) .. "/AccessCode", "rb")
- if accessCodeMatch(accessCodeFile) then
- accessCodeFile.close()
- return true
- else return false
- end
- end
- end
- end
- end
- end
- end
- function updateFailed(nFailed)
- failedFile = fs.open(".PasswordFiles/Failed", "w")
- failedFile.write(tostring(nFailed))
- failedFile.close()
- end
- function getFailed()
- if not fs.exists(".PasswordFiles/Failed") then return 0
- else
- failedFile = fs.open(".PasswordFiles/Failed", "r")
- if not failedFile then return 0 end
- nFailed = failedFile.readLine()
- nFailed = tonumber(nFailed)
- failedFile.close()
- if nFailed then return nFailed
- else return 0 end
- end
- end
- function checkFailed()
- if failed >= 3 then
- term.setCursorPos(1, 5)
- print("Too many failed attempts. Access Denied")
- print("Insert Access Disk to unlock")
- if checkDrive("all") then return true end
- while true do
- event, side = os.pullEvent("disk")
- if checkDrive(side) then return true end
- end
- end
- end
- failed = getFailed()
- while true do
- term.setCursorPos(10, 1)
- term.write(tostring(3 - failed))
- term.setCursorPos(1, termY)
- term.write("Failed Attempts:")
- for n = 1, 3 do
- if failed > n - 1 then
- term.write(" [X]")
- else
- term.write(" [ ]")
- end
- end
- term.setCursorPos(1, 3)
- term.clearLine()
- term.write("Password: ")
- updateFailed(failed)
- if checkFailed() then break end
- if read() == pass then
- print("Correct Password! Access Granted")
- sleep(1)
- break
- else
- failed = failed + 1
- end
- end
- updateFailed(0)
- term.clear()
- term.setCursorPos(1, 1)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement