Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function changerecoveryid() --Change id of the computer for the ftp recovery
- --needs to be implemented
- end
- function ftprecovery() --Ftp recovery of password using the ftp id
- --needs to be implemented
- end
- function changesafety() --Change safety code password
- --Needs to be tested
- term.clear()
- term.setCursorPos(1,1)
- write("New safety code: ")
- newpass = read("*")
- term.clear()
- term.setCursorPos(1,1)
- while true do
- term.clear()
- term.setCursorPos(1,1)
- write("Confirm code: ")
- confirm = read("*")
- if newpass == confirm then
- file = fs.open("login/safety","w")
- file.write(newpass)
- file.close()
- print("Password set..")
- sleep(2)
- term.clear()
- term.setCursorPos(1,1)
- break
- elseif newpass == "" then
- term.clear()
- term.setCursorPos(1,1)
- break
- else
- term.clear()
- term.setCursorPos(1,1)
- write("Confirmation failed. Please try again.")
- sleep(1)
- end
- end
- --Needs to be tested
- end
- function changepass() --Change password function
- --Needs to be tested
- term.clear()
- term.setCursorPos(1,1)
- write("New password: ")
- newpass = read("*")
- term.clear()
- term.setCursorPos(1,1)
- while true do
- term.clear()
- term.setCursorPos(1,1)
- write("Confirm password: ")
- confirm = read("*")
- if newpass == confirm then
- file = fs.open("login/password","w")
- file.write(newpass)
- file.close()
- print("Password set..")
- sleep(2)
- term.clear()
- term.setCursorPos(1,1)
- break
- elseif newpass == "" then
- term.clear()
- term.setCursorPos(1,1)
- break
- else
- term.clear()
- term.setCursorPos(1,1)
- write("Confirmation failed. Please try again.")
- sleep(1)
- end
- end
- --Needs to be tested
- end
- --The logged function (deletes .blocked, .nsafety, and resets attempts) and opens main control menu
- function logged()
- while true do
- fs.delete("login/.blocked")
- fs.delete("login/.nsafety")
- file = fs.open("login/attempt","w")
- file.write("0")
- file.close()
- term.clear()
- term.setCursorPos(1,1)
- print("Welcome!")
- print("1: Login")
- print("2: Change password")
- print("3: Change safety code")
- print("4: Change default computer id for pass recovery")
- choice = read()
- if choice == 1 then
- error()
- elseif choice == 2 then
- changepass()
- elseif choice == 3 then
- changesafety()
- elseif choice == 4 then
- changerecoveryid()
- end
- end
- end
- function first() --First time setup
- term.clear()
- term.setCursorPos(1,1)
- print("This is the first time you login!")
- sleep(2)
- term.clear()
- term.setCursorPos(1,1)
- print("Please enter your password")
- sleep(2)
- changepass()
- file = fs.open("login/.nft","w")
- file.close()
- term.clear()
- sleep(1)
- term.clear()
- term.setCursorPos(1,1)
- print("Please enter your safety code")
- sleep(2)
- changesafety()
- sleep(1)
- term.clear()
- term.setCursorPos(1,1)
- print("Please enter your remote recovery computer id")
- sleep(2)
- changerecoveryid()
- term.clear()
- term.setCursorPos(1,1)
- textutils.slowPrint("Initializing...")
- sleep(1)
- end
- --The unblocking function (deletes .blocked, .nsafety, and resets attempts)
- function unblock()
- fs.delete("login/.blocked")
- fs.delete("login/.nsafety")
- file = fs.open("login/attempt","w")
- file.write("0")
- file.close()
- term.clear()
- term.setCursorPos(1,1)
- print("Terminal unblocked! :D")
- sleep(2)
- end
- --The blocking function
- function block()
- while true do
- file = fs.open("login/.blocked","w")
- file.close()
- term.clear()
- term.setCursorPos(1,1)
- print("Terminal blocked!")
- print("1: Safety code (works only once and only one attempt)") --Safety code unblocks the system once
- print("2: Send bypass code to default computer") --Bypass code sent to default listed computer Bypasses the password and lets you change it (if the feature is enabled)
- print("Enter your option below:")
- choice = read()
- if choice == 1 then
- if not fs.exists("login/.nsafety") and fs.exists("login/safety") then
- file = fs.open("login/safety","r")
- correctsafecode = file.readAll()
- file.close()
- inputedsafecode = read("*")
- if inputedsafecode == correctsafecode then
- unblock()
- return
- else
- file = fs.open("login/.nsafety","w")
- file.close()
- end
- end
- if not fs.exists("login/safety") then
- term.clear()
- term.setCursorPos(1,1)
- print("Safety code was not set or deleted..")
- sleep(2)
- end
- if fs.exists("login/.nsafety") then
- term.clear()
- term.setCursorPos(1,1)
- print("Safety code was already entered..")
- sleep(2)
- end
- elseif choice == 2 then
- ftprecovery()
- --needs to be implemented
- elseif choice ~= 1 or choice ~= 2 then
- print("Incorrect choice")
- sleep(1)
- end
- end
- end
- function check()
- if fs.exists("login/.blocked") then block() end --Retains the block session
- if fs.exists("login/.nlocking") then --Checks if locking feature is on or off and also force repair .nft and attempts files
- lock = 0
- file = fs.open("login/attempt","w")
- file.write("0")
- file.close()
- file = fs.open("login/.nft","w")
- file.close()
- return 0
- else
- lock = 1
- --Checking password files and .nft data (the data that shows if the user is logging in for the first time)
- --And blocks and repair them and restore defaults if needed
- if not fs.exists("login/.nft") and fs.exists("login/password") then
- file = fs.open("login/.nft","w")
- file.close()
- end
- if not fs.exists("login/.nft") and not fs.exists("login/password") then
- first()
- end
- if fs.exists("login/.nft") and not fs.exits("login/password") then --Attempt to call nil!? ;(
- file = fs.open("login/.nft","w")
- file.close()
- term.clear()
- term.setCursorPos(1,1)
- print("Password was deleted or corrupted!")
- sleep(2)
- block()
- end
- --Checking the attempts and maxattempts files and blocks and repair them and restore defaults if needed
- if not fs.exists("login/attempt") and fs.exists("login/.nft") then
- file = fs.open("login/attempt","w")
- file.write("0")
- file.close()
- print("Attempts file was deleted or corrupted!")
- sleep(2)
- block()
- end
- if not fs.exists("login/attempt") and not fs.exists("login/.nft") then
- file = fs.open("login/attempt","w")
- file.write("0")
- file.close()
- end
- if not fs.exists("login/maxattempt") and not fs.exists("login/.nft") then
- file = fs.open("login/attempt","w")
- file.write("3")
- file.close()
- end
- if not fs.exists("login/maxattempt") and fs.exists("login/.nft") then
- file = fs.open("login/attempt","w")
- file.write("3")
- file.close()
- print("Maxattempts file was deleted or corrupted!")
- sleep(2)
- block()
- end
- --Read attempts and maxattempts from file
- file = fs.open("login/attempt","r")
- attempts = file.readAll()
- file.close()
- file = fs.open("login/maxattempt","r")
- maxattempts = file.readAll()
- file.close()
- end
- end
- --Counts attempts and blocks if limit exceeded
- function attempts()
- attempts = attempts + 1
- if attempts >= maxattempts then
- print("You exceeded the attempts limit!")
- sleep(2)
- block()
- end
- end
- --Main part of the program
- while true do
- check()
- if lock == 1 then
- term.clear()
- term.setCursorPos(1,1)
- print("")
- print("Terminal locked")
- print("")
- write("Password: ")
- file = fs.open("login/password","r")
- correctpass = file.readAll()
- file.close()
- pass = read("*")
- if pass == correctpass then logged()
- else
- attempts()
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment