Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local defaultInfo = {}
- --Prevents CTRL+T from terminating the program.
- --os.pullEvent = os.pullEventRaw
- --Reads the pconf file for info.
- function readpconf()
- file = fs.open("/.pconf", "r")
- ts = file.readAll()
- tss = textutils.unserialize(ts)
- file.close()
- end
- --Checks password file. If it doesn't exist, it will create one and prompt for a password.
- function check()
- if not fs.exists("/.pconf") then
- print("Config file not found.")
- print("Enter new password:")
- temp1 = tostring(read("*"))
- print("Enter output side:")
- temp2 = tostring(read())
- print("Enter open time:")
- temp3 = tonumber(read())
- print("Enter wrong password timeout:")
- temp4 = tonumber(read())
- table.insert(defaultInfo, temp1)
- table.insert(defaultInfo, temp2)
- table.insert(defaultInfo, temp3)
- table.insert(defaultInfo, temp4)
- file = fs.open("/.pconf", "w")
- ts = textutils.serialize(defaultInfo)
- file.write(ts)
- file.close()
- check()
- end
- end
- local function passwordCorrect()
- print("Password is correct.")
- redstone.setOutput(tss[2], true)
- sleep(tss[3])
- redstone.setOutput(tss[2], false)
- end
- local function passwordIncorrect()
- print("Password is INCORRECT.")
- sleep(tss[4])
- end
- local function prompt()
- term.clear()
- term.setCursorPos(1,1)
- print("Enter password:")
- attempt = tostring(read("*"))
- if attempt == tss[1] then
- passwordCorrect()
- else
- passwordIncorrect()
- end
- end
- check()
- readpconf()
- while true do
- prompt()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement