Advertisement
AquaJD

Bass

Jul 27th, 2017
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.63 KB | None | 0 0
  1. --[[
  2.  
  3.     Bass - Password Base
  4.     By Dave-ee Jones
  5.    
  6.     The password manager, allowing you to choose specific passwords to input into a program
  7.    
  8. --]]
  9.  
  10. local bRunAtStartup = false -- Replaces startup file, acting as a Password Manager behind programs
  11. local fRun = "test1" -- Program to run above Bass
  12. local kPassKey = keys.leftShift -- Key to press to detect the password needed
  13. local bHideInput = false -- Hides password input and stops cursor blinking (so people can't see how long password is)
  14. local bDiskAuth = false
  15. -- Passwords to detect based on program path
  16. local tPasswords = {
  17.     ["/test1"] = "bass",
  18.     ["/test2"] = "password",
  19.     ["/test3"] = "see? it's different"
  20. }
  21.  
  22. local bRunning = false
  23. local bDisk = false
  24. local sDiskPass = ""
  25.  
  26. if bRunAtStartup then
  27.     local prog = shell.getRunningProgram()
  28.     if prog == "startup" then
  29.         if fs.exists("/.bass") then
  30.             local file = fs.open("/.bass","r")
  31.             fs.delete(file.readLine())
  32.             file.close()
  33.             fs.delete("/.bass")
  34.             os.reboot()
  35.         end
  36.     else
  37.         if fs.exists("/startup") then
  38.             fs.move("/startup","/_startup")
  39.         end
  40.         local file = fs.open("/.bass","w")
  41.         file.writeLine("/"..prog)
  42.         file.close()
  43.         fs.copy("/"..prog,"/startup")
  44.         os.reboot()
  45.     end
  46. end
  47.  
  48. local function inputPassword()
  49.     while bRunning do
  50.         if tPasswords["/"..shell.getRunningProgram()] and not bDisk then
  51.             for i=1, #tPasswords["/"..shell.getRunningProgram()] do
  52.                 os.queueEvent("char",string.sub(tPasswords["/"..shell.getRunningProgram()],i,i))
  53.             end
  54.             os.queueEvent("key",keys.enter)
  55.         elseif bDisk and not sDiskPass == "" and bDiskAuth then
  56.             for i=1,#sDiskPass do
  57.                 os.queueEvent("char",string.sub(sDiskPass,i,i))
  58.             end
  59.             os.queueEvent("key",keys.enter)
  60.         end
  61.         if bHideInput then
  62.             term.setCursorBlink(false)
  63.             term.setTextColor(term.getBackgroundColor())
  64.         end
  65.         bRunning = false
  66.     end
  67. end
  68.  
  69. local function run()
  70.     if bRunAtStartup and fs.exists("/_startup") then
  71.         shell.run("/_startup")
  72.     else
  73.         shell.run(fRun)
  74.     end
  75. end
  76.  
  77. local co1 = coroutine.create(inputPassword)
  78. local co2 = coroutine.create(run)
  79.  
  80. local e = {}
  81. while true do
  82.     if bRunning then
  83.         coroutine.resume(co1,unpack(e))
  84.     end
  85.     coroutine.resume(co2,unpack(e))
  86.     e = { os.pullEvent() }
  87.     if e[1] == "key" and e[2] == kPassKey then
  88.         bRunning = true
  89.     elseif e[1] == "disk" and bDiskAuth then
  90.         bDisk = true
  91.         if fs.exists("/disk/bass_password") then
  92.             local _df = fs.open("/disk/bass_password")
  93.             sDiskPass = _df.readAll()
  94.             _df.close()
  95.         end
  96.     elseif e[1] == "disk_eject" and bDiskAuth then
  97.         bDisk = false
  98.         sDiskPass = ""
  99.     end
  100.     if coroutine.status(co2) == "dead" then
  101.         bRunning = false
  102.         break
  103.     end
  104. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement