LOGIN FEATURES
- Matches username and password to allow access to a program that requires credentials. (username is a file in users/[username] and password is a line of text within said file)
- Ignores blank entries for both username and password and after several failed attempts will kick you back to the main menu.
- Will ignore unknown usernames.
- Will lock down an account after three failed attempts to log in with an invalid password. (locked accounts are moved from users folder to pending folder and renamed to a random number for safe keeping. Will also check to ensure the random file name is not already in use)
- Admin override feature allows the system owner to enter the system shell without risk of major security breaches by utilizing a random password algorithm to generate new passwords upon each override request. (Current algorithm is (rnd + 11) * 83 where rnd = a random number generated by the system and displayed as an override code. Admin override login name is currently adminovrride)
- Reads the user account and applies an access level based on what the Admin has set for that user. (Currently only two access levels, admin and user, with more able to be added)
- Allows user to create an account by providing a username and password. The system then puts the information in a randomly generated file in the pending folder for safe keeping and admin approval at a later time. (Will check to ensure random file name is not already in use)
- Ignores blank entries for both username and password and after several failed attempts will kick you back to the main menu.
- Will ignore usernames already in use.
- Will disallow the creation of an account using the same login of the admin override feature.
- Matches password and confirm password to ensure the user selected a proper password for themselves.
- Ctrl-T is disallowed.
- Max input length is currently set to 12 but can be changed.
- Easy to modify to suit your needs.
- Self-sustained program in itself to allow easy integration to your system and it's other programs.
- Basic design to allow users of both basic and advanced computers to use this login system.
Two directories need to be pre-made prior to running. These directories are [users] and [pending] without the brackets and must be placed in the root of the system.
PLANNED FEATURES
Ability to determine whether the user is an admin or user. (Possibly other access levels as well)- Integration into an overall OS where the system boots and does a system check. (memory, file structure etc.) If the check fails it will initiate a system restore sequence from disk to restore the system to it's previous state including any back-up files saved.
Checks to see if the "pending" and the "users" directory exists. If not the program will create them.
Spoiler
local function readN(len, replaceChar)
len = len or 12
local input=""
local key = 0
term.setCursorBlink(true)
repeat
local e,p1 = os.pullEvent()
if e=="char" then
if #input < len then
input = input .. p1
term.write(replaceChar or p1)
end
elseif e=="key" and p1==keys.backspace and #input > 0 then
input = input:sub(1,#input-1)
local x,y = term.getCursorPos()
term.setCursorPos(x-1,y)
term.write(" ")
term.setCursorPos(x-1,y)
end
until p1==keys.enter
term.setCursorBlink(false)
return input
end
sid = 0
lockdown = 0
actc = ""
actpw = ""
actpc = ""
userlog = ""
userpas = ""
puselog = ""
prog = 0
function clear()
term.clear()
term.setCursorPos(1,1)
end
function menu(id, text)
if sid == id then
write">> "
else
write" "
end
print(text)
end
clear()
while prog == 0 do
os.pullEvent = os.pullEventRaw
rep1 = 0
rep2 = 0
rep3 = 0
rep4 = 0
rep5 = 0
rep6 = 0
ioerror = 0
term.setCursorPos(1, 12)
term.clearLine()
term.setCursorPos(1, 13)
term.clearLine()
term.setCursorPos(1, 14)
term.clearLine()
term.setCursorPos(1, 15)
term.clearLine()
term.setCursorPos(1, 16)
term.clearLine()
term.setCursorPos(1, 17)
term.clearLine()
term.setCursorPos(1,1)
print("|################################################|")
print("| BOUTECH SYSTEM LOGIN |")
print("| OS Version : 1.3 |")
print("|################################################|")
term.setCursorPos(13,7)
print("|------------------------|")
term.setCursorPos(13,8)
print("| |")
term.setCursorPos(13,9)
print("| |")
term.setCursorPos(13,10)
print("| |")
term.setCursorPos(13,11)
print("|------------------------|")
term.setCursorPos(16,8)
menu(0, "Login")
term.setCursorPos(16,9)
menu(1, "Create Account")
term.setCursorPos(16,10)
menu(2, "Shutdown")
event, key = os.pullEvent("key")
if key == 200 then
if sid == 0 then
sid = sid+2
elseif sid == 1 then
sid = sid-1
elseif sid == 2 then
sid = sid-1
end
elseif key == 208 then
if sid == 2 then
sid = sid-2
elseif sid == 1 then
sid = sid+1
elseif sid == 0 then
sid = sid+1
end
elseif key == 28 then
if sid == 0 then
term.setCursorPos(13, 12)
print("| Enter Credentials. |")
term.setCursorPos(13, 13)
print("| |")
term.setCursorPos(13, 14)
print("| |")
term.setCursorPos(13, 15)
print("| |")
term.setCursorPos(13, 16)
print("| |")
term.setCursorPos(13, 17)
print("|------------------------|")
while rep5 == 0 do
term.setCursorPos(1, 14)
term.clearLine()
term.setCursorPos(1, 16)
term.clearLine()
term.setCursorPos(13, 16)
print("| |")
term.setCursorPos(13, 14)
print("| |")
term.setCursorPos(15, 14)
write("Username: ")
userlog = readN()
if userlog == "adminovrride" then
rnd = math.random(100, 500)
term.setCursorPos(1, 18)
term.clearLine()
term.setCursorPos (17, 18)
print("Override Code: ".. rnd)
apass = tostring((rnd + 11) * 83)
term.setCursorPos(1, 16)
term.clearLine()
term.setCursorPos(13, 16)
print("| |")
term.setCursorPos(15, 16)
write("Password: ")
ovrpass = readN(12, "*")
if ovrpass == apass then
term.setCursorPos(1, 18)
term.clearLine()
term.setCursorPos(15, 18)
print("Override Successful...")
sleep(3)
term.clear()
term.setCursorPos(1, 1)
rep5 = rep5+1
rep6 = rep6+1
prog = prog+1
else
term.setCursorPos(1, 18)
term.clearLine()
term.setCursorPos(15, 18)
print(" Override Failed...")
sleep(1)
rep5 = rep5+1
rep6 = rep6+1
sid = 0
end
else
if userlog == "" then
term.setCursorPos(1, 18)
term.clearLine()
term.setCursorPos(18, 18)
print("Invalid Username")
sleep(1)
ioerror = ioerror+1
if ioerror == 3 then
rep5 = rep5+1
rep6 = rep6+1
sid = 0
else
end
else
ioerror = 0
ulog = fs.exists("users/".. userlog)
if ulog == true then
term.setCursorPos(1, 16)
term.clearLine()
term.setCursorPos(13, 16)
print("| |")
term.setCursorPos(15, 16)
write("Password: ")
userpas = readN(12, "*")
if userpas == "" then
term.setCursorPos(1, 18)
term.clearLine()
term.setCursorPos(15, 18)
print("Invalid Password Entry")
sleep(1)
ioerror = ioerror+1
term.setCursorPos(1, 18)
term.clearLine()
if ioerror == 3 then
rep5 = rep5+1
sid = 0
else
end
else
ulog = io.open("users/".. userlog, "r") or nil
pass = ulog and ulog:read()
ulog:close()
if (pass and pass==userpas) then
term.setCursorPos(1, 18)
term.clearLine()
term.setCursorPos(16, 18)
print(" Login Success...")
rep5 = rep5+1
rep6 = rep6+1
sid = 0
sleep(2)
--Put your shell.run([PROGRAM]) here to move into the system you had locked by this program.
else
if lockdown < 2 then
term.setCursorPos(1, 18)
term.clearLine()
term.setCursorPos(16, 18)
print(" Wrong Password")
sleep(1)
if userlog == puselog then
lockdown = lockdown+1
else
lockdown = 0
puselog = userlog
lockdown = lockdown+1
end
else
while rep6 == 0 do
term.setCursorPos(15, 18)
rnd = tostring(math.random(101, 999))
if not fs.exists("pending/".. rnd) then
fs.move("users/".. userlog, "pending/".. rnd)
term.setCursorPos(1, 18)
term.clearLine()
term.setCursorPos(15, 18)
print(" Lockdown Ref #: "..rnd)
sleep(1)
ulog = fs.open("pending/".. rnd, "a")
ulog.writeLine("Username: ".. userlog)
ulog.close()
rep6 = rep6+1
rep5 = rep5+1
sid = 0
else
end
end
end
end
end
else
term.setCursorPos(14, 18)
print(" Bad/Unknown Username")
sleep(1)
end
end
end
end
elseif sid == 1 then
term.setCursorPos(13, 12)
print("| Submit Account Info. |")
term.setCursorPos(13, 13)
print("| |")
term.setCursorPos(13, 14)
print("| |")
term.setCursorPos(13, 15)
print("| |")
term.setCursorPos(13, 16)
print("| |")
term.setCursorPos(13, 17)
print("|------------------------|")
while rep1 == 0 do
term.setCursorPos(1, 14)
term.clearLine()
term.setCursorPos(13, 14)
print("| |")
term.setCursorPos(15, 14)
write("Username: ")
input = readN()
actc = input
actex = fs.exists("users/".. actc)
if input == "adminovrride" then
term.setCursorPos(1, 18)
term.clearLine()
term.setCursorPos(18, 18)
print("Invalid Username")
sleep(1)
ioerror = ioerror+1
if ioerror == 3 then
rep1 = 1
rep2 = 1
rep3 = 1
sid = 0
else
end
else
if input == "" then
term.setCursorPos(1, 18)
term.clearLine()
term.setCursorPos(18, 18)
print("Invalid Username")
sleep(1)
ioerror = ioerror+1
if ioerror == 3 then
rep1 = 1
rep2 = 1
rep3 = 1
sid = 0
else
end
elseif actex == true then
term.setCursorPos(1, 18)
term.clearLine()
term.setCursorPos(15, 18)
print (" Username Unavailable")
sleep(1)
else
ioerror = 0
rep1 = 1
end
end
end
while rep2 == 0 do
while rep3 == 0 do
term.setCursorPos(15, 15)
write("Password: ")
input = readN(12, "*")
if input == "" then
term.setCursorPos(1, 18)
term.clearLine()
term.setCursorPos(15, 18)
print("Invalid Password Entry")
sleep(1)
ioerror = ioerror+1
if ioerror == 3 then
rep1 = 1
rep2 = 1
rep3 = 1
else
end
else
ioerror = 0
actpw = input
rep3 = 1
rep2 = 1
end
end
term.setCursorPos(13, 16)
print("| |")
term.setCursorPos(15, 16)
write("Confirm : ")
input = readN(12, "*")
actpc = input
if (actpc) == (actpw) then
while rep4 == 0 do
rnd = tostring(math.random(1011, 9999))
if not fs.exists("pending/".. rnd) then
file = fs.open("pending/".. rnd, "w")
file.writeLine(actc)
file.writeLine(actpw)
file.close()
rep4 = rep4+1
else
end
end
term.setCursorPos(1, 18)
term.clearLine()
term.setCursorPos(13, 18)
print(" Pending... Ref #: ", rnd)
sleep(1)
ioerror = 0
rep2 = 1
sid = 0
else
term.setCursorPos(1, 18)
term.clearLine()
term.setCursorPos(15, 18)
print("Password Doesn't Match")
sleep(1)
rep2 = 0
ioerror = ioerror+1
if ioerror == 3 then
rep1 = 1
rep2 = 1
rep3 = 1
else
end
end
end
elseif sid == 2 then
term.setCursorPos(13,14)
print("|########################|")
term.setCursorPos(13,15)
print("# SYSTEM SHUTTING DOWN!! #")
term.setCursorPos(13,16)
print("|########################|")
sleep(3)
os.shutdown()
end
end
end
PASTEBIN
- Pastebin get tK3ikweu (You can also get this code (Ctrl-T function is allowed) from Pastebin)