Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- aUser = {}
- aPass = {}
- nUserList = 0
- local function inputBox(len, x, y, mask)
- local bInput = true
- local sOutput = ""
- term.setCursorPos(x,y)
- while bInput == true do
- local sEvent, param = os.pullEvent()
- if sEvent == "key" then
- if param == 28 then
- if string.len(sOutput) > 0 then
- bInput = false
- end
- elseif param == 14 then
- sOutput = string.sub(sOutput,1,string.len(sOutput)-1)
- term.setCursorPos(x+string.len(sOutput),y)
- io.write(" ")
- term.setCursorPos(x+string.len(sOutput),y)
- end
- end
- if sEvent == "char" then
- if string.len(sOutput) < len then
- sOutput = sOutput .. param
- term.setCursorPos(x,y)
- if not mask then
- io.write(sOutput)
- else
- for n=1,string.len(sOutput) do
- io.write("*")
- end
- end
- end
- end
- end
- return sOutput
- end
- local function drawBox(x, y, w, h)
- for n=0,h-1 do
- term.setCursorPos(x,y+n)
- if n == 0 then
- io.write("+")
- for n2=1,w-2 do
- io.write("-")
- end
- io.write("+")
- elseif n == h-1 then
- io.write("+")
- for n2=1,w-2 do
- io.write("-")
- end
- io.write("+")
- else
- io.write("|")
- for n2=1,w-2 do
- io.write(" ")
- end
- io.write("|")
- end
- end
- end
- local function textAt(x,y, str)
- term.setCursorPos(x,y)
- io.write(str)
- end
- local function form(str, msg, mask)
- term.clear()
- term.setCursorBlink(true)
- if msg ~= "" then
- textAt(26-(string.len(msg)/2),7,msg)
- end
- drawBox(16,9,20,3)
- textAt(14-string.len(str),10,str..":")
- local sData = inputBox(16, 18, 10, mask)
- return sData
- end
- local function checkPass()
- return fs.exists("ACCOUNTS.F")
- end
- local function loadPass()
- nUserList = 0
- aUser = {}
- aPass = {}
- local file = io.open( "ACCOUNTS.F", "r" )
- local sLineU = file:read()
- local sLineP = file:read()
- while sLineU do
- nUserList = nUserList + 1
- table.insert(aUser, sLineU)
- table.insert(aPass, sLineP)
- sLineU = file:read()
- sLineP = file:read()
- end
- file:close()
- end
- local function writePass()
- local file = io.open( "ACCOUNTS.F", "w" )
- for n=1,nUserList do
- file:write(aUser[n] .. "\n")
- file:write(aPass[n] .. "\n")
- end
- file:close()
- end
- local function login()
- local nWrong = 0
- local SFormMsg = "Please enter your username & password."
- local bCorrect = false
- local sUser
- local sPass
- while not bCorrect do
- sUser = form("Username", SFormMsg, false)
- sPass = form("Password", SFormMsg, true)
- for n=1,nUserList do
- if string.lower(sUser) == string.lower(aUser[n]) then
- if sPass == aPass[n] then
- bCorrect = true
- end
- end
- end
- if not bCorrect then
- nWrong = nWrong + 1
- if nWrong == 3 then
- msg = "Too many failed attemps! Shutting down."
- textAt(26-(string.len(msg)/2),13,msg)
- sleep(5)
- os.shutdown()
- end
- msg = "Username and/or password incorrect!"
- textAt(26-(string.len(msg)/2),13,msg)
- sleep(2)
- end
- end
- return sUser, bCorrect
- end
- local function newUser()
- local sUser = ""
- local sPass = ""
- local sPassconf = "!!!!!!!!!!!!!!!!!!"
- local bValid = false
- local bConflict = false
- local SFormMsg = "Account Creation: Enter new username."
- while not bValid do
- bValid = false
- sUser = ""
- while string.len(sUser) < 3 do
- sUser = form("Username", SFormMsg, false)
- if string.len(sUser) < 3 then
- SFormMsg = "Username must have at least 3 characters."
- end
- bConflict = false
- if nUserList > 0 then
- for n=1,nUserList do
- if string.lower(sUser) == string.lower(aUser[n]) then
- SFormMsg = "Username already exists! Choose another."
- bConflict = true
- end
- end
- end
- if not bConflict then
- bValid = true
- end
- end
- end
- SFormMsg = "Account Creation: Enter new password."
- while sPass ~= sPassConf do
- while string.len(sPass) < 5 do
- sPass = form("Password", SFormMsg, true)
- if string.len(sPass) < 5 then
- SFormMsg = "Password must have at least 5 characters."
- end
- end
- SFormMsg = "Account Creation: Re-enter your password."
- sPassConf = form("Password", SFormMsg, true)
- if sPass ~= sPassConf then
- sPass = ""
- sPassconf = "!!!!!!!!!!!!!!!!!!"
- SFormMsg = "Passwords do not match! Create new password."
- end
- end
- table.insert(aPass, sPass)
- table.insert(aUser, sUser)
- nUserList = nUserList + 1
- writePass()
- end
- local bNotFirst = checkPass()
- if bNotFirst then
- loadPass()
- x, y = login()
- else
- newUser()
- x, y = login()
- end
- term.clear()
- term.setCursorPos(1,1)
- print(x)
- print(y)
Add Comment
Please, Sign In to add comment