Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- 1lann's First Ever Publically Available Program
- -- Published on Janurary 5 2012
- -- Unmodified, Original from: http://www.minecraftforum.net/topic/895297-computercraft-program-library/page__st__60#entry11702697
- --[[ Setup instructions:
- Setting Up:
- 1. Make sure you set the program as the startup program
- 2. The current configuration is that the right of the computer will control the vault/safe lock, while the back will control what will happen if a person runs out of login attempts. Guide: When the left side is on, it will open the vault. When the back is on, it will activate the what will happen if a person runs out of login attempts.
- Setting up the lock:
- 1. Run startup
- 2. Set a password at prompt
- 3. Put stuff in your vault, then lock it]]
- function readyToLock(n)
- write("Ready? ")
- command = read()
- if command == "lock" then
- print "Ok, locking your safe!"
- redstone.setOutput("right", false)
- lockSafe()
- end
- print "Sorry I don't understand what you said, try again"
- readyToLock()
- end
- function doLock(n)
- num = 0
- file = io.open("attempts.dat", "w")
- file:write(num)
- file:close()
- redstone.setOutput("right", false)
- redstone.setOutput("back", true)
- print "[SYSTEM LOCKDOWN]"
- nothing = read()
- doLock()
- end
- function lockSafe(n)
- term.clear()
- file = io.open("password.dat", "w")
- file:write(password)
- file:close()
- file = io.open("attemptset.dat", "w")
- file:write(numset)
- file:close()
- file = io.open("attempts.dat", "w")
- file:write(num)
- file:close()
- if attemptEnabled == true then aten = "true"
- end
- if attemptEnabled == false then aten = "false"
- end
- file = io.open("attempten.dat", "w")
- file:write(aten)
- file:close()
- redstone.setOutput("right", false)
- print " [SAFE LOCKED]"
- print " [PRESS ENTER TO UNLOCK]"
- print " SCAL v.1"
- enter = read()
- passwordAuth()
- end
- function passwordAuth(n)
- if num < 0.1 then
- doLock()
- end
- print "Enter your password to unlock your safe"
- if attemptEnabled == true then
- print ("You have " .. num .. " attempts remaining")
- end
- write "Password: "
- entry = read("*")
- if entry == password then
- print "Password Accepted!"
- sleep(2)
- num = numset
- file = io.open("attempts.dat", "w")
- file:write(num)
- file:close()
- redstone.setOutput("right", true)
- launchMenu()
- end
- print "Password Incorrect!"
- sleep(2)
- if attemptEnabled == true then
- numb = num
- num = numb - 1
- if num < 0.1 then
- doLock()
- end
- end
- lockSafe()
- end
- function changePassword(n)
- term.clear()
- print "Please enter you current password"
- print "Or type back to go back"
- write "Current Password: "
- cpassword = read("*")
- if cpassword == password then
- term.clear()
- write "New password: "
- password = read()
- print "New password set!"
- file = io.open("password.dat", "w")
- file:write(password)
- file:close()
- sleep(2)
- launchMenu()
- end
- if cpassword == "back" then
- launchMenu()
- end
- print "Password Incorrect! Locking safe"
- sleep(3)
- lockSafe()
- end
- function changeAttempts(n)
- term.clear()
- if attemptEnabled == true then
- result = "enabled"
- end
- if attemptEnabled == false then
- result = "disabled"
- end
- print ("Currently, attempts are " .. result)
- print ("and you can do " .. numset .. " login attempts")
- print "\nType toggle to enable/disable attempts."
- print "\nType set to set the number of login attempts one can do"
- print "\nType back to go back"
- cattempts = read()
- if cattempts == "toggle" then
- if attemptEnabled == true then
- attemptEnabled = false
- print "Attempts are now disabled!"
- if attemptEnabled == true then aten = "true"
- end
- if attemptEnabled == false then aten = "false"
- end
- file = io.open("attempten.dat", "w")
- file:write(aten)
- file:close()
- sleep(3)
- launchMenu()
- end
- if attemptEnabled == false then
- attemptEnabled = true
- print "Attempts are now enabled!"
- if attemptEnabled == true then aten = "true"
- end
- if attemptEnabled == false then aten = "false"
- end
- file = io.open("attempten.dat", "w")
- file:write(aten)
- file:close()
- sleep(3)
- launchMenu()
- end
- end
- if cattempts == "back" then
- launchMenu()
- end
- if cattempts == "set" then
- setAttempts()
- end
- print "Not a valid option!"
- sleep(3)
- changeAttempts()
- end
- function setAttempts(n)
- term.clear()
- print "Enter a number above 0 to set the number of login attempts"
- print "Type anything else to go back"
- nmbr = read()
- entern = tonumber(nmbr)
- if entern == nil then
- changeAttempts()
- end
- if entern > 0 then
- numset = entern
- num = entern
- print ("You can now only do " .. numset .. " attempts")
- file = io.open("attemptset.dat", "w")
- file:write(numset)
- file:close()
- file = io.open("attempts.dat", "w")
- file:write(num)
- file:close()
- sleep(4)
- launchMenu()
- end
- print "The number must be above 0"
- sleep(3)
- changeAttempts()
- end
- function lockdown(n)
- term.clear()
- print "This will lockdown your safe and you will have"
- print "to break it down. This would also stop the"
- print "computer from operating, if you are sure,"
- print "enter your password"
- print "or type back to go back"
- write "Password: "
- cpassword = read("*")
- if cpassword == password then
- term.clear()
- doLock()
- end
- if cpassword == "back" then
- launchMenu()
- end
- print "Password Incorrect! Locking safe"
- sleep(3)
- lockSafe()
- end
- function launchMenu(n)
- term.clear()
- file = io.open("password.dat", "w")
- file:write(password)
- file:close()
- file = io.open("attemptset.dat", "w")
- file:write(numset)
- file:close()
- file = io.open("attempts.dat", "w")
- file:write(num)
- file:close()
- if attemptEnabled == true then aten = "true"
- end
- if attemptEnabled == false then aten = "false"
- end
- file = io.open("attempten.dat", "w")
- file:write(aten)
- file:close()
- print "Welcome! The actions you can do are:"
- print "changepassword - Change your current password"
- print "changeattempts - Change the number of login"
- print "attempts you can do"
- print "lockdown - WARNING: Does a system lockdown"
- print "lock - locks your safe"
- write "Action: "
- action = read()
- if action == "lock" then
- print "Locking safe..."
- sleep(2)
- lockSafe()
- end
- if action == "changepassword" then
- changePassword()
- end
- if action == "changeattempts" then
- changeAttempts()
- end
- if action == "lockdown" then
- lockdown()
- end
- print "Not a valid option!"
- sleep(3)
- launchMenu()
- end
- passwordexist = false
- if fs.exists("password.dat") then
- passwordexist = true
- file = io.open("password.dat", "r")
- password = file:read()
- file:close()
- file = io.open("attemptset.dat", "r")
- numsetz = file:read()
- file:close()
- numset = tonumber(numsetz)
- file = io.open("attempts.dat", "r")
- numz = file:read()
- file:close()
- num = tonumber(numz)
- file = io.open("attempten.dat", "r")
- aten = file:read()
- file:close()
- if aten == "true" then attemptEnabled = true
- end
- if aten == "false" then attemptEnabled = false
- end
- end
- if passwordexist == false then
- attemptEnabled = true
- num = 4
- numset = 4
- redstone.setOutput("right", true)
- redstone.setOutput("back", false)
- print "Oh hey there, I'm SCAL, which means"
- print "Secure Computer Authorized Lock"
- print "I see you're new here, go ahead and set a new"
- write "Password: "
- password = read ()
- term.clear()
- print "Ok you better remember that!"
- print "Go ahead and type in \"lock\" when you're ready"
- print "to lock your safe"
- readyToLock()
- end
- redstone.setOutput("right", false)
- redstone.setOutput("back", false)
- passwordAuth()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement