Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.pullEvent = os.pullEventRaw
- -- Local Variables --
- local root = ".ComputerLock/Lock/"
- -- Functions --
- --[[ Password ]]--
- function invalid()
- term.clear()
- term.setCursorPos(1,1)
- print("Invalid Input!")
- os.sleep(2)
- os.reboot()
- end
- function uninstall()
- print("\nDo You Want To Uninstall ComputerLock? Yes / No")
- write("\n> ")
- local input = read()
- if input == "Yes" or input == "yes" then
- write("\nEnter Current Password: ")
- local input = read("*")
- pr = fs.open(root .. "password", "r")
- Password = pr.readLine()
- pr.close()
- if input == Password then
- fs.delete(".ComputerLock")
- fs.delete("startup")
- print("\nComputerLock Uninstalled!")
- os.reboot()
- else
- print("\nIncorrect Password!")
- os.sleep(2)
- os.reboot()
- end
- elseif input == "No" or input == "no" then
- os.reboot()
- else
- invalid()
- end
- end
- function reSetNewPass()
- print("\nPasswords Do Not Match!")
- os.sleep(2)
- setNewPass()
- end
- function setNewPass()
- write("\nEnter New Password: ")
- NewPass = read("*")
- write("Confirm New Password: ")
- ConfirmNewPass = read("*")
- if NewPass == ConfirmNewPass then
- fs.delete(root .. "password")
- pw = fs.open(root .. "password", "w")
- pw.writeLine(ConfirmNewPass)
- pw.close()
- print("\nNew Password Set!")
- os.sleep(2)
- login()
- else
- reSetNewPass()
- end
- end
- function changePass()
- print("\nDo You Want To Change The Password? Yes / No")
- write("\n> ")
- local input = read()
- if input == "Yes" or input == "yes" then
- write("\nEnter Current Password: ")
- local input = read("*")
- pr = fs.open(root .. "password", "r")
- Password = pr.readLine()
- pr.close()
- if input == Password then
- setNewPass()
- else
- print("\nIncorrect Password!")
- os.sleep(2)
- os.reboot()
- end
- elseif input == "No" or input == "no" then
- os.reboot()
- else
- invalid()
- end
- end
- function reSetPass()
- print("\nPasswords Do Not Match!")
- os.sleep(2)
- setPass()
- end
- function setPass()
- fs.makeDir(".ComputerLock")
- fs.makeDir(".ComputerLock/Lock")
- write("\nPlease Enter Your Password: ")
- local PassEnter = read("*")
- write("Please Confirm Your Password: ")
- local PassConfirm = read("*")
- if PassEnter == PassConfirm then
- pw = fs.open(root .. "password", "w")
- pw.write(PassConfirm)
- pw.close()
- print("\nPassword Has Been Set!")
- os.sleep(2)
- login()
- else
- reSetPass()
- end
- end
- function prolong()
- print("\nOk")
- os.sleep(1)
- print("\nExiting ComputerLock")
- os.sleep(2)
- term.clear()
- term.setCursorPos(1,1)
- print("CraftOS")
- return
- end
- function correctPass()
- print("\nCorrect Password!")
- os.sleep(2)
- term.clear()
- term.setCursorPos(1,1)
- print("CraftOS")
- return
- end
- function incorrectPass()
- print("\nIncorrect Password!")
- os.sleep(1)
- os.reboot()
- end
- function reLogin()
- login()
- end
- function login()
- term.clear()
- term.setCursorPos(1,1)
- print("ComputerLock 2.0")
- print("\nThis Computer Is Locked!")
- print("Press [Enter] To Unlock!")
- repeat
- event, key = os.pullEvent("key")
- os.sleep(0.1)
- until key == 28 or key == 210 or key == 211
- if key == 28 then
- write("\nEnter The Password: ")
- local input = read("*")
- pr = fs.open(root .. "password", "r")
- Password = pr.readLine()
- pr.close()
- if input == Password then
- correctPass()
- else
- incorrectPass()
- end
- elseif key == 210 then
- changePass()
- elseif key == 211 then
- uninstall()
- end
- end
- -- Main --
- term.clear()
- term.setCursorPos(1,1)
- if fs.exists(root .. "password") then
- login()
- elseif not fs.exists(root .. "password") then
- print("Your ComputerLock Password Has Not Been Set!")
- os.sleep(1)
- print("\nWould You Like To Set It Now? Yes / No")
- write("\n> ")
- local input = read()
- if input == "Yes" or input == "yes" then
- setPass()
- elseif input == "No" or input == "no" then
- prolong()
- else
- invalid()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment