Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.loadAPI("sha")
- local passPath = "passwords" --Change this if you want a different password file
- if not fs.exists(passPath) then --Create a password file
- local f = fs.open(passPath, "w")
- f.write(textutils.serialize({}))
- f.close()
- end
- local function secureInput( mask, prestring )
- local l = true
- term.setCursorBlink(true)
- local prestring = prestring or ""
- local str = ""
- local sx, sy = term.getCursorPos()
- while l do
- local e, a, b, c, d = os.pullEventRaw()
- if e == "char" then
- str = str .. a
- elseif e == "key" then
- if a == 14 then
- str = str:sub(1, -2)
- elseif a == 28 then
- l = false
- term.setBackgroundColour( colours.black )
- term.setTextColour( colours.white )
- print()
- return str
- end
- end
- term.setCursorPos(sx, sy)
- term.setBackgroundColour( colours.white )
- term.setTextColour( colours.black )
- term.clearLine()
- if mask then
- write( prestring .. " > " .. string.rep(mask, #str) )
- else
- write( prestring .. " > " .. str )
- end
- end
- end
- local function getPass( usr )
- local f = fs.open(passPath,"r")
- local pwds = textutils.unserialize( f.readAll() )
- f.close()
- if pwds[ usr ] then
- return pwds[ usr ]
- else
- return false
- end
- end
- local function login( usr, pwd )
- local info = getPass( usr )
- if info then
- if sha.sha256( pwd .. info.salt ) == info.pwd then
- return true
- else
- return false
- end
- else
- return false
- end
- end
- --Login script--
- local loop = true
- while loop do
- local username = secureInput( nil, "username" )
- local password = secureInput( "x", "password" )
- if login( username, password ) then
- print("Login successfull!")
- loop = false
- break
- --DO SOMETHING
- else
- print("Login failed.")
- --REMOVE these 2 lines below so that the loop continues after incorrect login, once proven program works.
- loop = false
- break
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement