Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Variables
- local userauth = "debug"
- local passauth = "debug"
- local fullauth = 0
- local admin = false
- -- Functions start here
- function signin()
- while true do
- sleep(1)
- cls()
- print("Enter your credentials to sign in.")
- print(" ")
- print("Username: ")
- print("Password: ")
- term.setCursorPos(11,3)
- local username = read()
- globaluser = username
- term.setCursorPos(11,4)
- local password = read("*")
- if fs.exists("appsupport/passwordlock/users/"..username) then
- userauth = "pass"
- else
- userauth = "fail"
- end
- if userauth == "pass" then
- if fs.exists("appsupport/passwordlock/users/"..username.."/password.txt") then
- -- good file found
- else
- term.setCursorPos(1,6)
- print("Account incorrectly configured! Contact an administrator.")
- end
- passcheck = fs.open("appsupport/passwordlock/users/"..username.."/password.txt", "r")
- if userauth == "pass" then
- if password == (passcheck.readAll()) then
- passcheck.close()
- passauth = "pass"
- break
- else
- passauth = "fail"
- term.setCursorPos(1,6)
- print("Incorrect username or password.")
- end
- end
- end
- end
- end
- function admintoolsconsole()
- cls()
- print("Tools")
- print(" ")
- print(" [ Console ] ")
- print(" Settings ")
- print(" Manage Users ")
- print(" Shutdown Computer ")
- print(" ")
- print(" Access the console, you'll need to reboot to access this menu again.")
- local event, param1 = os.pullEvent()
- if param1 == 200 then
- admintoolssd()
- elseif param1 == 208 then
- admintoolssettings()
- elseif param1 == 28 then
- -- Nothing, let them into console.
- end
- end
- function admintoolssettings()
- cls()
- print("Tools")
- print(" ")
- print(" Console ")
- print(" [ Settings ]")
- print(" Manage Users ")
- print(" Shutdown Computer ")
- print(" ")
- print(" Change your security settings.")
- local event, param1 = os.pullEvent()
- if param1 == 200 then
- admintoolsconsole()
- elseif param1 == 208 then
- admintoolsusers()
- elseif param1 == 28 then
- settingsmenu1()
- end
- end
- function admintoolsusers()
- cls()
- print("Tools")
- print(" ")
- print(" Console ")
- print(" Settings ")
- print(" [ Manage Users ] ")
- print(" Shutdown Computer ")
- print(" ")
- if admin == true then
- print(" Manage the other users on your computer.")
- else
- print(" You do not have permission to access this.")
- end
- local event, param1 = os.pullEvent()
- if param1 == 200 then
- admintoolssettings()
- elseif param1 == 208 then
- admintoolssd()
- elseif param1 == 28 then
- if admin == true then
- -- this happens
- elseif admin == false then
- -- this happens
- end
- end
- end
- function admintoolssd()
- cls()
- print("Tools")
- print(" ")
- print(" Console ")
- print(" Settings ")
- print(" Manage Users ")
- print(" [ Shutdown Computer ] ")
- print(" ")
- print(" This will shutdown your computer.")
- local event, param1 = os.pullEvent()
- if param1 == 200 then
- admintoolsusers()
- elseif param1 == 208 then
- admintoolsconsole()
- elseif param1 == 28 then
- os.shutdown()
- end
- end
- function settingsmenu1()
- cls()
- print("Settings Menu")
- print(" ")
- print(" [ Change Password ] ")
- print(" Change Username ")
- print(" ")
- print(" Return to Tools Menu ")
- local event, param1 = os.pullEvent()
- if param1 == 200 then
- --()
- elseif param1 == 208 then
- settingsmenu2()
- elseif param1 == 28 then
- changepass()
- end
- end
- function settingsmenu2()
- cls()
- print("Settings Menu")
- print(" ")
- print(" Change Password ")
- print(" [ Change Username ] ")
- print(" ")
- print(" Return to Tools Menu ")
- local event, param1 = os.pullEvent()
- if param1 == 200 then
- settingsmenu1()
- elseif param1 == 208 then
- settingsmenu3()
- elseif param1 == 28 then
- changeuser()
- end
- end
- function settingsmenu3()
- cls()
- print("Settings Menu")
- print(" ")
- print(" Change Password ")
- print(" Change Username ")
- print(" ")
- print(" [ Return to Tools Menu ] ")
- local event, param1 = os.pullEvent()
- if param1 == 200 then
- settingsmenu2()
- elseif param1 == 208 then
- settingsmenu1()
- elseif param1 == 28 then
- admintoolssettings()
- end
- end
- function changepass()
- cls()
- write("Enter a new password here: ")
- changepass = read()
- fs.delete("appsupport/passwordlock/users/"..globaluser.."/password.txt")
- passchange = fs.open("appsupport/passwordlock/users/"..globaluser.."/password.txt", "w")
- passchange.writeLine(changepass)
- passchange.close()
- print("Password changed to '"..changepass.."'.")
- sleep(2)
- settingsmenu1()
- end
- function changeuser()
- cls()
- write("Enter a new username here: ")
- changeuser = read()
- print(" ")
- write("Changing some files.")
- fs.makeDir("appsupport/passwordlock/temppass")
- sleep(.3)
- write(".")
- fs.copy("appsupport/passwordlock/users/"..globaluser.."/password.txt", "appsupport/passwordlock/temppass")
- sleep(.3)
- write(".")
- fs.delete("appsupport/passwordlock/users/"..globaluser)
- sleep(.3)
- write(".")
- fs.makeDir("appsupport/passwordlock/user/"..changeuser)
- sleep(.3)
- write(".")
- fs.copy("appsupport/passwordlock/temppass/password.txt", "appsupport/passwordlock/users/"..globaluser.."/password.txt")
- if admin == true then
- fs.delete("appsupport/passwordlock/admins/"..globaluser)
- fs.makeDir("appsupport/passwordlock/admins/"..changeuser)
- end
- globaluser = changeuser
- print("Username changed to '"..changeuser.."'.")
- sleep(2)
- settingsmenu2()
- end
- function cls()
- term.clear()
- term.setCursorPos(1,1)
- end
- -- Functions stop here
- cls()
- -- Check for new users
- if fs.exists("appsupport/passwordlock/users") then
- -- Users file found
- else
- cls()
- print("It looks like this is your first time using this program.")
- print(" ")
- write("Please enter the username you'd like: ")
- local newuser = read()
- fs.makeDir("appsupport/passwordlock/users")
- fs.makeDir("appsupport/passwordlock/users/"..newuser)
- while true do
- cls()
- write("Please set a password for your account: ")
- newpass = read()
- if newpass == "" then
- print("You can't have a blank password!")
- sleep(2)
- elseif newpass == " " then
- sleep(2)
- print("You can't have a blank password!")
- sleep(2)
- elseif newpass == "password" then
- print("Pick a more secure password!")
- sleep(2)
- elseif newpass == "qwertyuiop" then
- print("Pick a more secure password!")
- sleep(2)
- elseif newpass == "asdfghjkl" then
- print("Pick a more secure password!")
- sleep(2)
- elseif newpass == "zxcvbnm" then
- print("Pick a more secure password!")
- sleep(2)
- else
- break
- end
- end
- print("Password set as '"..newpass.."'.")
- passcreate = fs.open("appsupport/passwordlock/users/"..newuser.."/password.txt", "w")
- passcreate.writeLine(newpass)
- passcreate.close()
- fs.makeDir("appsupport/passwordlock/admins/"..newuser)
- newuserowner = fs.open("appsupport/passwordlock/admins/"..newuser.."/"..newuser, "w")
- newuserowner.writeLine("default")
- newuserowner.close()
- end
- signin()
- term.setCursorPos(1,6)
- print("Signing in...")
- -- local username = globaluser / UNCOMMENT LATER!
- sleep(2)
- cls()
- if fs.exists("appsupport/passwordlock/admins/"..globaluser) then
- admin = true
- end
- admintoolsconsole()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement