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