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

Password Set (Useful on servers)

Started by ImNutzForCoal, 07 August 2012 - 12:18 PM
ImNutzForCoal #1
Posted 07 August 2012 - 02:18 PM
On the two tekkit servers I play, I tend to be "incharge" of the CC setups for people. When they request a passworded door, I tend to veer away from them telling me the password, as it could look bad if they ever get griefed.

I like to use the following script, saved generally as "pwset" or "setpw". In the example, it is named "pwset"

-- I like to call this program "pwset" or to that effect
term.clear()
term.setCursorPos(1,1)
print("Please enter your desired password: ")
pw1 = read("*") -- For the newbies, this will make the text appear as *s rather than letters
sleep(1)
print("Please confirm your password: ")
pw2 = read("*")
sleep(1)
if pw1 == pw2 then
os.setComputerLabel(pw2)
os.reboot()
else
print("Passwords did not match. Please try again")
shell.run("pwset")
end
-- I like to use ComputerLabel as the password because it stays set even after the reboot, and is the simplist form I know. Even if someone managed to see the startup code, they would not see a password.

This works for me every time.
Bobder22 #2
Posted 07 August 2012 - 05:14 PM
Not sure why, but this line of code doesnt like to work: attempt to call nil

os.setComputerLabel(pw2)
Im a LUA nub or I would try and fix this ;)/>/>

EDIT: It seems to be a problem with CC itself. I've tried using the label program, but it returns the same error.
ImNutzForCoal #3
Posted 07 August 2012 - 07:36 PM
to add it to a passworded door:

term.clear()
term.setCursorPos(1,1)
print("Password:")
pw = read("*")
if pw == os.getComputerLabel() then
redstone.setOutput("SIDE", true)
sleep(3)
redstone.setOutput("SIDE", false)
else
os.shutdown()
end
ImNutzForCoal #4
Posted 07 August 2012 - 07:37 PM
Not sure why, but this line of code doesnt like to work: attempt to call nil

os.setComputerLabel(pw2)
Im a LUA nub or I would try and fix this ;)/>/>

EDIT: It seems to be a problem with CC itself. I've tried using the label program, but it returns the same error.

Try reinstalling CC? or updating?
Bobder22 #5
Posted 07 August 2012 - 08:05 PM
Not sure why, but this line of code doesnt like to work: attempt to call nil

os.setComputerLabel(pw2)
Im a LUA nub or I would try and fix this ;)/>/>

EDIT: It seems to be a problem with CC itself. I've tried using the label program, but it returns the same error.

Try reinstalling CC? or updating?

Yeah, It works fine now :(/>/>
Cranium #6
Posted 07 August 2012 - 10:11 PM
A few suggestions on your code:

function pwSet()
term.clear()
while true do --will keep this going until it all works
term.setCursorPos(1,1)
print("Please enter your desired password: ")
local pwtemp = read("*") -- using local is always good
--sleep functions not needed since it is waiting on input from user
print("Please confirm your password: ")
local pwtemp2 = read("*")-- more local
--no sleep for this computer... HAHAHAHA!!!
  if pwtemp1 == pwtemp2 then
    password = pwtemp
    break
  else
    print("Passwords did not match. Please try again")
  end
end
You should be able to use this within your code and just call back to the function(pwSet()) and variable(password) later.