local old_pullEvent = os.pullEvent
os.pullEvent = os.pullEventRaw
term.clear()
term.setCursorPos(1, 1)
term.write ("Please Enter Username: ")
username=read("*")
if username == "simplaysgames" then
print("User Existing")
sleep(2.0)
term.clear()
if username == "BackDoor" then
print("User Existing")
sleep(2.0)
term.write("Please Enter Password")
PasswordUBackDoor = read("*")
if PasswordUBreak == "BackDoor1" then
print("Password correct, access granted!")
print("Script Broken")
return
else
print("User not registered, if you think this is an error please contact moderator")
sleep(5.0)
term.clear()
term.setCursorPos(1, 1)
print("Please Try Again!")
sleep(2.0)
shell.run("halla")
end
term.write("Please Enter Password: ")
Password =read()
if Password == "Haha" then
print("Password correct, access granted!")
redstone.setOutPut(left, true)
sleep(5.0)
redstone.setOutPut(left, true)
else
print("Password incorrect, access denied!")sleep(2.0)
term.clear()
term.setCursorPos(1, 1)
print("Please Try Again")
sleep(2.0)
shell.run("halla")
os.reboot()
end
end
end
This is a read-only snapshot of the ComputerCraft forums,
taken in April 2020.
My password script dosn't work correctly can get broken
Started by SimPlaysGames, 29 June 2014 - 06:39 AMPosted 29 June 2014 - 08:39 AM
[Okey my problem is that if i type in brake as a password the whole program gets exited out and i don't want that how do i fix this? Yes i know its a little bit messy!
Edited by
Posted 29 June 2014 - 12:42 PM
First of all, please use code tags
And post the error code you're getting, it makes it easier for us to help you.
It seems that you want a 'while true do' loop to repeat this, else it just checks for the username and password one time and then exits.
Useful links for the stuff above
else/elseif
loops
locals
[.CODE] Put code between here [./CODE] (Without the dots)
And post the error code you're getting, it makes it easier for us to help you.
It seems that you want a 'while true do' loop to repeat this, else it just checks for the username and password one time and then exits.
while true do
-- Put code here
end
And learn to use else/elseif and locals
local username = read()
if username == "SomeUser" then
-- do something
elseif username == "SomeUser1" then
-- do something else
else
-- do something if the username didn't match any of the above
end
Useful links for the stuff above
else/elseif
loops
locals
Edited on 29 June 2014 - 10:43 AM
Posted 30 June 2014 - 04:39 PM
Okey if i use the code you just gave me how can i add soo they also has to type in a password?
local username = read()
if username == "SomeUser" then
-- do something
elseif username == "SomeUser1" then
-- do something else
else
-- do something if the username didn't match any of the above
end
Edited by
Posted 30 June 2014 - 06:15 PM
Well you could do it like thisOkey if i use the code you just gave me how can i add soo they also has to type in a password?local username = read() if username == "SomeUser" then -- do something elseif username == "SomeUser1" then -- do something else else -- do something if the username didn't match any of the above end
-- First, get both the username and the pass
local username = read()
local password = read("*")
-- then check the username and pass
if username == "SomeUser" then
if password = "SomePassword" then
-- do something when it's the correct password
else
-- do something when it's a wrong password
end
elseif username == "SomeUser1" then
if password == "SomePassword1" then
-- correct password
else
-- wrong password
end
else
-- unknown username
end
But a better approach when having multiple users is to put them in a table
local users = {
["SomeUser"] = "SomePass";
["SomeUser1"] = "SomePass1";
}
local function check( username, password )
for user, pass in pairs( users ) do
if username == user then
if password == pass then
return true
else
return false, "wrong password"
end
end
end
return false, "unknown username"
end
local username = read()
local password = read("*")
local ok, err = check( username, password )
if ok then
-- correct password and username
else
-- wrong username or password
print( err )
end
Posted 01 July 2014 - 09:26 AM
Spoiler
local users = { ["SomeUser"] = "SomePass"; ["SomeUser1"] = "SomePass1"; } local function check( username, password ) for user, pass in pairs( users ) do if username == user then if password == pass then return true else return false, "wrong password" end end end return false, "unknown username" end local username = read() local password = read("*") local ok, err = check( username, password ) if ok then -- correct password and username else -- wrong username or password print( err ) end
Why use a loop? Can't you access the items directly?
local users = {
["SomeUser"] = "SomePass";
["SomeUser1"] = "SomePass1";
}
local username = read()
local password = read("*")
local ok, err = true, ""
local thisUser = users[username]
if thisUser == nil then
ok = false
err = "User does not exist"
elseif thisUser ~= password then
ok = false
err = "Password is wrong"
end
if ok then
-- correct password and username
else
-- wrong username or password
print( err )
end
You might also want to look at GravityScore's SHA256 implementation to hash the passwords so they are not in plain text.
You might also want to read this post on multiple users.
Edited on 01 July 2014 - 07:27 AM
Posted 01 July 2014 - 07:50 PM
I just updated mu script but there is a error on line 50 and 51 : bios:339: [string "hei"]:50: '(' exected
and is says: bios:339: [string "hei"]:51: '(' exected
If you see more errors please alert me :)/> thanks
local old_pullEvent = os.pullEvent
os.pullEvent = os.pullEventRaw
term.clear()
term.setCursorPos(1,1)
function getUsername()
term.write("Please Enter Your Username: ")
username = read()
term.clear()
term.setCursorPos(1,1)
if username == "sim4bass" then
print("User Existing, Proceeding To Password Check")
getPassword(Hallo)
elseif username == "BackDoor"then
print("User Existing, Proceeding To Password Check")
getPasswordBackDoor()
else
print ("Username Not Existing If You Think This Is An Error Feel Free Too Contact A Owner")
sleep(2.0)
getUsername()
end
end
function getPassword(checkPass)
local Password = ""
term.write("Please Enter Your Password: ")
Password = read()
if Password == checkPass then
print("Password Correct, Access Granted ")
redstone.setOutPut(left ,true)
sleep(5.0)
redstone.setOutPut(left ,false)
else
print ("Password Incorrect, Access Denied")
getUsername()
end
end
function getPasswordBackDoor()
term.write("Please Enter Your Password: ")
if Password == "BackDoor=Break" then
print("Password Correct, Access Granted ")
return
else
print ("Password Incorrect, Access Denied")
getUsername()
end
end
end
getUsername()
and is says: bios:339: [string "hei"]:51: '(' exected
If you see more errors please alert me :)/> thanks
local old_pullEvent = os.pullEvent
os.pullEvent = os.pullEventRaw
term.clear()
term.setCursorPos(1,1)
function getUsername()
term.write("Please Enter Your Username: ")
username = read()
term.clear()
term.setCursorPos(1,1)
if username == "sim4bass" then
print("User Existing, Proceeding To Password Check")
getPassword(Hallo)
elseif username == "BackDoor"then
print("User Existing, Proceeding To Password Check")
getPasswordBackDoor()
else
print ("Username Not Existing If You Think This Is An Error Feel Free Too Contact A Owner")
sleep(2.0)
getUsername()
end
end
function getPassword(checkPass)
local Password = ""
term.write("Please Enter Your Password: ")
Password = read()
if Password == checkPass then
print("Password Correct, Access Granted ")
redstone.setOutPut(left ,true)
sleep(5.0)
redstone.setOutPut(left ,false)
else
print ("Password Incorrect, Access Denied")
getUsername()
end
end
function getPasswordBackDoor()
term.write("Please Enter Your Password: ")
if Password == "BackDoor=Break" then
print("Password Correct, Access Granted ")
return
else
print ("Password Incorrect, Access Denied")
getUsername()
end
end
end
getUsername()
Edited on 03 July 2014 - 07:14 AM
Posted 02 July 2014 - 02:48 AM
next time please just edit the previous post to fix formatting errors, instead of making a new reply.
Posted 02 July 2014 - 09:40 PM
Just a question, you can edit other peoples posts right? if so then can you add some code tags to the post above you? :P/>next time please just edit the previous post to fix formatting errors, instead of making a new reply.
And SimPlaysGames, You can add code tags by doing this
[.CODE]
print("Put your code between these tags")
print("Remove the dots ofcourse")
[./CODE]
Posted 03 July 2014 - 06:02 AM
Ok i think i found your problem, you are telling the computer that the only acceptable password is "haha" and if it is not then run this program before you shutdown. once the computer starts back up it will run the startup file( which in your case just needs to be shell.run("hala") and if there is not a startup file made the computer will automatically resort to the startup file located in the rom directory.
in simpler terms take the os.reboot() command out.
in simpler terms take the os.reboot() command out.
Edited on 03 July 2014 - 04:07 AM
Posted 03 July 2014 - 09:22 AM
it looks like there is a problem with the redstone part here:
function getPassword(checkPass)
local Password = ""
term.write("Please Enter Your Password: ")
Password = read()
if Password == checkPass then
print("Password Correct, Access Granted ")
redstone.setOutPut(left ,true)
sleep(5.0)
redstone.setOutPut(left ,false)
anyone have an idea on how to do it?
function getPassword(checkPass)
local Password = ""
term.write("Please Enter Your Password: ")
Password = read()
if Password == checkPass then
print("Password Correct, Access Granted ")
redstone.setOutPut(left ,true)
sleep(5.0)
redstone.setOutPut(left ,false)
anyone have an idea on how to do it?
Posted 03 July 2014 - 09:27 AM
it looks like there is a problem with the redstone part here:
function getPassword(checkPass)
local Password = ""
term.write("Please Enter Your Password: ")
Password = read()
if Password == checkPass then
print("Password Correct, Access Granted ")
redstone.setOutPut(left ,true)
sleep(5.0)
redstone.setOutPut(left ,false)
anyone have an idea on how to do it?
It should be
redstone.setOutput("left",true)
not
redstone.setOutPut(left ,true)
(The differences are the capital P and the side has to be a string.Edited on 03 July 2014 - 07:27 AM
Posted 03 July 2014 - 09:32 AM
is there a methode to get the program to display the username on top?
local old_pullEvent = os.pullEvent
os.pullEvent = os.pullEventRaw
term.clear()
term.setCursorPos(1,1)
function getUsername()
term.write("Please Enter Your Username: ")
username = read()
term.clear()
term.setCursorPos(1,1)
if username == "sim4bass" then
print("User Existing, Proceeding To Password Check")
getPassword(Hallo)
elseif username == "BackDoor"then
print("User Existing, Proceeding To Password Check")
getPasswordBackDoor()
else
print ("Username Not Existing If You Think This Is An Error Feel Free Too Contact A Owner")
sleep(2.0)
getUsername()
end
end
function getPassword(checkPass)
local Password = ""
term.write("Please Enter Your Password: ")
if Password == checkPass then
print("Password Correct, Access Granted ")
redstone.setOutPut(left ,true)
sleep(5.0)
redstone.setOutPut(left ,false)
else
print ("Password Incorrect, Access Denied")
getUsername()
end
end
end
function getPasswordBackDoor()
term.write("Please Enter Your Password: ")
if Password == "BackDoor=Break" then
print("Password Correct, Access Granted ")
break
else
print ("Password Incorrect, Access Denied)
getUsername()
end
end
end
getUsername()
Edited by
Posted 03 July 2014 - 11:10 AM
You should indent your code and use
tags
Edited on 03 July 2014 - 09:11 AM