This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Sgt.Mike's profile picture

Password Tutorial

Started by Sgt.Mike, 06 November 2013 - 12:06 PM
Sgt.Mike #1
Posted 06 November 2013 - 01:06 PM
Hey guys,i just wanted to make a Short Tutorial on how to make Passwords
All you need to do is the following


-- This is a quick explanation
print "Please type in the Correct Password"
password = read("*")
if password == "Yourpassword" then
print "Access Granted"
elseif password == "Secondarypassword" then
print "Access Granted(Secondary Password)"
else
print "Access Not Granted"
end

Actually using Password(Behind read) is not Required but i suggest you just use Password.If you put something else instead then you have to put the same word after the if statement.Elseif is a Statement too.Its basically Else + If = Elseif.It practicaly means
"Otherwise if you do this"…You can also use "redstone.setOutput("side", true/false) to toggle Redstone Signals on and off in the Direction you want.This is useful for Using a Password to open a door…Example Code


print "Please type the Correct Password"
password = read("*")
if password = "Yourpassword" then
print "Door Opened!"
rs.setOutput("bottom", true )
sleep(3)
rs.setOutput("bottom, false )
print "Door Closed"
else
print "Wrong Password"
end

This code works 100% Fine and is tested by me.in the "rs.setOutput("side", boolean)" thing.You can use almost anything for sides.In my case i used "bottom"…Supposing that the Door is right under the Computer.And dont forget to use "sleep(..)" after you open the Redstone Signal for as much as you want and then make sure you close it.Otherwise the Signal will keep staying open.And make sure you put "else" right after you end the code.I mean the code if the Password is correct.If you dont then all passwords will be considered Correct or Wrong.I dont know i havent tested it.Hope you enjoyed my Tutorial…
Agoldfish #2
Posted 06 November 2013 - 02:32 PM
It is probably better to make the password a variable. I'm sure you know how but just in case anyone else doesn't…


local yourpass = "this is default"
print "Please type the Correct Password"
password = read("*")
if password == yourpass then
print "Door Opened!"
rs.setOutput("bottom", true )
sleep(3)
rs.setOutput("bottom, false )
print "Door Closed"
else
print "Wrong Password"
end
Also, in line 3 in the second code, it should be

if password == "Yourpassword" then
--code
Not

if password = "Yourpassword" then
--code
Sgt.Mike #3
Posted 06 November 2013 - 02:37 PM
Oh.Yeah thanks for fixing me…
Lyqyd #4
Posted 06 November 2013 - 05:12 PM
This "tutorial" falls well short of the minimum quality requirements. If it is not significantly improved soon, I will remove it.
ElvishJerricco #5
Posted 06 November 2013 - 05:58 PM
To improve it, you should talk about how having the password in plain text is a huge security hole and how hashing and salting fixes that.
Agoldfish #6
Posted 06 November 2013 - 06:39 PM
Sorry if I'm coming off as a jerk, but you should probably add

os.pullEvent = os.pullEventRaw
At the top of each code to prevent Ctrl+t.
1vannn #7
Posted 08 November 2013 - 10:37 PM
When I code my password applications, I take a look at the HTTP API. I have my own webserver where I can do PHP checks to see if the user entered a correct, or incorrect answer. This way not only does it add additional security for the user because you can't view PHP code unless your viewing it server side, and it's not stored on the server where the owner of the server can possibly find it and compromise your system. Using the HTTP API also allows you to use MySQL for user account creation. This way, you can have multiple usernames and passwords to one system and at the same time, creating a system that can easily be changed since MySQL is hosted on your webserver, not the Minecraft Server.