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

Door Lock With Password Set

Started by jolbol1, 19 February 2013 - 04:24 AM
jolbol1 #1
Posted 19 February 2013 - 05:24 AM
Ok so i am trying to make a password door, i have got all the door and password lock setup however i would like to know how i would be able to make it so the first tim they use the computer it asks them to set a password instead of me editing the code.
Lyqyd #2
Posted 19 February 2013 - 06:41 AM
Split into new topic.
Madster #3
Posted 19 February 2013 - 08:51 PM

local setpass

print("Please define your desired password:")
setpass = read()
clear()


theoriginalbit #4
Posted 19 February 2013 - 08:55 PM
the best/easiest way to do it is to have a file, if the file doesn't exist, assume that its the programs first run. if the file exists, load the password from it. :)/>
Shrooblord #5
Posted 20 February 2013 - 04:23 AM
the best/easiest way to do it is to have a file, if the file doesn't exist, assume that its the programs first run. if the file exists, load the password from it. :)/>
Which, in code, would be something along the lines of:
Spoiler

if fs.exists("pass.wrd") then
  local passfile = fs.open("pass.wrd", "r")
  password = passfile.readLine()
  passfile.close()
else
  local passfile = fs.open("pass.wrd", "w")
  print("Create your password and press Enter to confirm.")
  password = read("*")
  passfile.write(tostring(password))
  passfile.close()
end

Of course this isn't very secure - but I'll leave you to figure that one out. ;)/>