-- So Far UnnamedOS Startup
-- By DanJZ0404
os.pullEvent = os.pullEventRaw
vNum = "v04" --For getVersion func.
function getVersion() -- returns version number
print("UnnamedOS "..vNum)
end
function userManage() -- This contains user data.
usernames = {"dan", "admin", "foo"}
passwords = {"pass", "12345", "bar"} -- Creates pass table.
end
function newScr() --
term.clear()
term.setCursorPos(1,1)
end
function requestLogin()
userManage()
newScr()
print("Username:")
term.setCursorPos(11,1)
uIn = (read) -- input
print("Password:")
term.setCursorPos(11,2)
pIn = (read("*"))
for l = 1, 3 do
if uIn==usernames[l] and pIn==passwords[l] then
term.setCursorPos(1,18)
print("Access Granted.")
sleep(3)
newScr()
error("Access Granted. - UnnamedOS "..vNum)
end
end
end
requestLogin()
Help with Login System - OS
Started by Zee, Jul 17 2013 11:40 PM
11 replies to this topic
#1
Posted 17 July 2013 - 11:40 PM
Right. I'm working on an OS, and it includes a login system for startup. The problem is, I CANNOT figure out what I can do to reboot the machine when password is incorrect.. Also, props to whoever thinks up the awesomest name!
EDIT: Code didn't copy/paste right. Reload in about 10 minutes.
#2
Posted 17 July 2013 - 11:43 PM
If your press and hold Ctrl + R at the same time for a couple of seconds, the computer should reboot.
#4
Posted 17 July 2013 - 11:49 PM
Would this change work?
if uIn==usernames[l] and pIn==passwords[l] then
term.setCursorPos(1,18)
print("Access Granted.")
sleep(3)
newScr()
error("Access Granted. - DanOS v03")
elseif not uIn==usernames[l] and pIn==passwords[1] or not uIn==usernames[2] and pIn==passwords[2] or not uIn==usernames[3] and pIn==passwords[3] then
os.reboot()
end
#5
Posted 18 July 2013 - 02:23 AM
DanJZ0404, on 17 July 2013 - 11:49 PM, said:
Would this change work?
if uIn==usernames[l] and pIn==passwords[l] then
term.setCursorPos(1,18)
print("Access Granted.")
sleep(3)
newScr()
error("Access Granted. - DanOS v03")
elseif not uIn==usernames[l] and pIn==passwords[1] or not uIn==usernames[2] and pIn==passwords[2] or not uIn==usernames[3] and pIn==passwords[3] then
os.reboot()
endIt would, but dat indentation c_c
Call it KrytenOS!
#6
Posted 18 July 2013 - 04:18 AM
for l = 1, 3 do
if uIn==usernames[l] and pIn==passwords[l] then
term.setCursorPos(1,18)
print("Access Granted.")
sleep(3)
newScr()
error("Access Granted. - UnnamedOS "..vNum)
end
end
by this bit of code you have limited the OS login system to only 3 users and passwords. -- bad idea.try this instead
for i = 1, #usernames do
if uIn==usernames[i] and pIn==passwords[i] then
term.setCursorPos(1,18)
print("Access Granted.")
sleep(3)
newScr()
printError("Access Granted. - UnnamedOS "..vNum) -- Gives a neater exit
error()
end
end
-- we exit the loop and no results so...
print("Failed")
sleep(3)
os.reboot()
Also this function is a little wastefull...
function requestLogin()
userManage()
newScr()
print("Username:")
term.setCursorPos(11,1)
uIn = (read) -- input
print("Password:")
term.setCursorPos(11,2)
pIn = (read("*"))
for l = 1, 3 do
if uIn==usernames[l] and pIn==passwords[l] then
term.setCursorPos(1,18)
print("Access Granted.")
sleep(3)
newScr()
error("Access Granted. - UnnamedOS "..vNum)
end
end
end
requestLogin()
it basically programs itself then will never finish because you want the os to reboot if it fails to login.
this is a better way of doing it...
-- instead of a function lets call this as the main program its linear...
userManage()
newScr()
print("Username:")
term.setCursorPos(11,1)
uIn = (read) -- input
print("Password:")
term.setCursorPos(11,2)
pIn = (read("*"))
for i = 1, #usernames do
if uIn==usernames[i] and pIn==passwords[i] then
term.setCursorPos(1,18)
print("Access Granted.")
sleep(3)
newScr()
printError("Access Granted. - UnnamedOS "..vNum) -- Gives a neater exit
error()
end
end
-- we exit the loop and no results so...
print("Failed")
sleep(3)
os.reboot()
#7
Posted 18 July 2013 - 08:08 PM
Don't use os.reboot() as a loop.
#8
Posted 19 July 2013 - 04:56 AM
DanJZ0404, on 17 July 2013 - 11:45 PM, said:
No. That's not what I meant. I want the computer to reboot if the password is incorrect.
hence I did os.reboot()
Otherwise I would suggest doing a set varible to true, use varible as while true do loop and loop untill password is correct then set varible to false. (which is a better way of doing it)
I would myself write the code like this...
-- instead of a function lets call this as the main program its linear...
local valid = false -- Make our loop work
while not valid do -- While the value valid is not true.. loop
userManage()
newScr()
print("Username:")
term.setCursorPos(11,1)
uIn = read() -- get username
print("Password:")
term.setCursorPos(11,2)
pIn = read("*") -- get password
for i = 1, #usernames do
if uIn==usernames[i] and pIn==passwords[i] then
term.setCursorPos(1,18)
print("Access Granted.")
sleep(3)
newScr()
valid = true -- Finish loop and allow script to continue
print("Access Granted. - UnnamedOS "..vNum) -- Allow access
break
end
end
if not valid then
print("Failed")
sleep(3)
end
end
-- More OS program after success
As for a Name... DanOs
#10
Posted 25 January 2014 - 03:54 PM
Code #1
while true do
if uIn==usernames[l] and pIn==passwords[l] then
term.setCursorPos(1,18)
print("Access Granted.")
sleep(3)
newScr()
print("Access Granted. - UnnamedOS "..vNum)
error()
else
os.reboot()
end
end
Code #2-- So Far UnnamedOS Startup
-- By DanJZ0404[/size]
[size=4]os.pullEvent = os.pullEventRaw
vNum = "v04" --For getVersion func.
function getVersion() -- returns version number
print("UnnamedOS "..vNum)
end
function userManage() -- This contains user data.
usernames = {"dan", "admin", "foo"}
passwords = {"pass", "12345", "bar"} -- Creates pass table.
end
function newScr() --
term.clear()
term.setCursorPos(1,1)
end
function requestLogin()
userManage()
newScr()[/size]
[size=4]while true do
print("Username:")
term.setCursorPos(11,1)
uIn = (read) -- input
print("Password:")
term.setCursorPos(11,2)
pIn = (read("*"))
while true do
if uIn==usernames[l] and pIn==passwords[l] then
term.setCursorPos(1,18)
print("Access Granted.")
sleep(3)
newScr()
print("Access Granted. - UnnamedOS "..vNum)[/size]
error()
end
end
end
requestLogin()
end
#11
Posted 25 January 2014 - 06:21 PM
Here is a simple answer to your question
if uIn==usernames[l] and pIn==passwords[l] then
term.setCursorPos(1,18)
print("Access Granted.")
sleep(3)
newScr()
error("Access Granted. - UnnamedOS "..vNum)
else -- quit the program
os.reboot()
end
Edited by LuaCrawler, 25 January 2014 - 06:22 PM.
#12
Posted 26 January 2014 - 10:41 PM
Can you let us know if you got it to work?
immibis is correct, why should you use os.reboot as a loop when you can run your own loop and add things like an action on too many failed passwords?
immibis is correct, why should you use os.reboot as a loop when you can run your own loop and add things like an action on too many failed passwords?
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











