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

[Password 2.0] I have little problem

Started by johnthetiger, 28 June 2014 - 09:45 PM
johnthetiger #1
Posted 28 June 2014 - 11:45 PM
Hello, I invented a software password using a database on another computer but I have a slight problem, it does not function correctly, could you help me. Here is the code:
Database:

rednet.open("right")
local pass = rednet.receive()

if pass == "Pa$sw0rd" then
print("received!")
rednet.send(111, "on")
print("sended")
sleep(20)
end
os.reboot()

computer containing the password:

rednet.open("right")
print("Password?")
pass = read()
rednet.send(112, pass)
print("Acces to server…")
sleep(5)

commande = rednet.receive()
if commande == "on" then
redstone.setOutput("top", true)
end

thank you for Avence for your help. its been over a week that I try my error without finding
Lyqyd #2
Posted 29 June 2014 - 01:05 AM
Moved to Ask a Pro.
Agoldfish #3
Posted 29 June 2014 - 01:09 AM
I don't see "Pa$sw0rd" defined anywhere.
Dog #4
Posted 29 June 2014 - 01:26 AM
@Agoldfish - "Pa$sw0rd" is the actual password and is supplied by the user via 'pass = read()'

@johnthetiger - start by removing 'sleep(5)' - your program is 'sleeping' when the other program transmits, so it misses the transmission.
Edited on 28 June 2014 - 11:27 PM
flaghacker #5
Posted 29 June 2014 - 07:17 AM
Your usage of rednet.receive() is wrong.

local id, message, protocol = rednet.receive(timeout)
You are only capturing the first return of the function, and calling it "pass". Then you compare it to the password. Of course, they will never be the same.

Also, instead of os.reboot() I would use a while true do loop. If you're not familiar with them, here's a tutorial:
http://computercraft.info/wiki/index.php?title=Loops

Also, please put you code in code tags, for easier readability.
This is done like this:

[CODE ]
--code goes here

Without spaces before the brackets.
Edited on 29 June 2014 - 05:26 AM
Dog #6
Posted 29 June 2014 - 07:31 AM
Your usage of rednet.receive() is wrong.

local id, message, protocol = rednet.receive(timeout)
You are only capturing the first return of the function, and calling it "pass". Then you compare it to the password. Of course, they will never be the same.

Good catch, flaghacker - a bit annoyed that I missed that when I just pointed that out in another thread the other day :)/>
Edited on 29 June 2014 - 05:33 AM
flaghacker #7
Posted 29 June 2014 - 08:36 AM
Sure, that can happen to everyone.

@OP Don't forget to also remove that sleep