Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Bass - Password Base
- By Dave-ee Jones
- The password manager, allowing you to choose specific passwords to input into a program
- --]]
- local bRunAtStartup = false -- Replaces startup file, acting as a Password Manager behind programs
- local fRun = "test1" -- Program to run above Bass
- local kPassKey = keys.leftShift -- Key to press to detect the password needed
- local bHideInput = false -- Hides password input and stops cursor blinking (so people can't see how long password is)
- local bDiskAuth = false
- -- Passwords to detect based on program path
- local tPasswords = {
- ["/test1"] = "bass",
- ["/test2"] = "password",
- ["/test3"] = "see? it's different"
- }
- local bRunning = false
- local bDisk = false
- local sDiskPass = ""
- if bRunAtStartup then
- local prog = shell.getRunningProgram()
- if prog == "startup" then
- if fs.exists("/.bass") then
- local file = fs.open("/.bass","r")
- fs.delete(file.readLine())
- file.close()
- fs.delete("/.bass")
- os.reboot()
- end
- else
- if fs.exists("/startup") then
- fs.move("/startup","/_startup")
- end
- local file = fs.open("/.bass","w")
- file.writeLine("/"..prog)
- file.close()
- fs.copy("/"..prog,"/startup")
- os.reboot()
- end
- end
- local function inputPassword()
- while bRunning do
- if tPasswords["/"..shell.getRunningProgram()] and not bDisk then
- for i=1, #tPasswords["/"..shell.getRunningProgram()] do
- os.queueEvent("char",string.sub(tPasswords["/"..shell.getRunningProgram()],i,i))
- end
- os.queueEvent("key",keys.enter)
- elseif bDisk and not sDiskPass == "" and bDiskAuth then
- for i=1,#sDiskPass do
- os.queueEvent("char",string.sub(sDiskPass,i,i))
- end
- os.queueEvent("key",keys.enter)
- end
- if bHideInput then
- term.setCursorBlink(false)
- term.setTextColor(term.getBackgroundColor())
- end
- bRunning = false
- end
- end
- local function run()
- if bRunAtStartup and fs.exists("/_startup") then
- shell.run("/_startup")
- else
- shell.run(fRun)
- end
- end
- local co1 = coroutine.create(inputPassword)
- local co2 = coroutine.create(run)
- local e = {}
- while true do
- if bRunning then
- coroutine.resume(co1,unpack(e))
- end
- coroutine.resume(co2,unpack(e))
- e = { os.pullEvent() }
- if e[1] == "key" and e[2] == kPassKey then
- bRunning = true
- elseif e[1] == "disk" and bDiskAuth then
- bDisk = true
- if fs.exists("/disk/bass_password") then
- local _df = fs.open("/disk/bass_password")
- sDiskPass = _df.readAll()
- _df.close()
- end
- elseif e[1] == "disk_eject" and bDiskAuth then
- bDisk = false
- sDiskPass = ""
- end
- if coroutine.status(co2) == "dead" then
- bRunning = false
- break
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement