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

Make passwords look like ******

Started by Traffic_Warden, 10 June 2012 - 07:39 PM
Traffic_Warden #1
Posted 10 June 2012 - 09:39 PM
Hi,

How do i make passwords look like this (****) when i enter it for my password door lock?

And how can i make it so you can't terminate it unless you enter the correct password?


Thanks
MysticT #2
Posted 10 June 2012 - 09:48 PM
To hide the password (show *** instead) you need to use read("*") instead of read() (Note: io.read("*") wont work, you have to use read("*")).
And to prevent termination you can use this:

local oldPullEvent = os.pullEvent
os.pullEvent = os.pullEventRaw
-- Insert your code here
os.pullEvent = oldPullEvent
This way you prevent termination even using functions like sleep or read.
Traffic_Warden #3
Posted 10 June 2012 - 09:59 PM
Perfect got them two things to work.

If I enter my password wrong it goes to a blank screen, can i get it to automatically reset to startup if the password is wrong?
ComputerCraftFan11 #4
Posted 10 June 2012 - 10:02 PM
Perfect got them two things to work.

If I enter my password wrong it goes to a blank screen, can i get it to automatically reset to startup if the password is wrong?

You can try this:

term.clear()
term.setCursorPos(1,1)--clear the screen
if read("*") == "your password" then
  --whatever u want
else
  print("Wrong!")
  sleep(1)
  shell.run("startup")
end
MysticT #5
Posted 10 June 2012 - 10:03 PM
Perfect got them two things to work.

If I enter my password wrong it goes to a blank screen, can i get it to automatically reset to startup if the password is wrong?

You can try this:

term.clear()
term.setCursorPos(1,1)--clear the screen
if read("*") == "your password" then
  --whatever u want
else
  print("Wrong!")
  sleep(1)
  shell.run("startup")
end
Only if you want to crash the computer. That's not the way to do it.
You need use a loop, so the program doesn't end after you enter the password:

while true do
  term.clear()
  term.setCursorPos(1, 1)
  write("Enter password: ")
  if read("*") == "YourPassword" then
    print("Correct password")
  else
    print("Incorrect password")
  end
end
Traffic_Warden #6
Posted 10 June 2012 - 10:07 PM
Gotcha, one last thing, How do i copy my startup with my door lock onto a floppy?
ComputerCraftFan11 #7
Posted 10 June 2012 - 10:11 PM
Gotcha, one last thing, How do i copy my startup with my door lock onto a floppy?

Put a disk drive by the PC, put a floppy inside of the disk drive and on the PC, type this:

copy *name of door lock* disk/
(Type that into the shell)
MysticT #8
Posted 10 June 2012 - 10:12 PM
From the shell, type:
> cp <ProgramName> disk/<ProgramName>

From a program:

fs.copy("<PrograName>", "/disk/<ProgramName>")
Traffic_Warden #9
Posted 10 June 2012 - 10:16 PM
Can't terminate my startup now when i enter the correct password, have i done something wrong?
ComputerCraftFan11 #10
Posted 10 June 2012 - 10:20 PM
If you used Wolvan's code, he forgot a "break" so the loop will go forever. Try this:

while true do
  term.clear()
  term.setCursorPos(1, 1)
  write("Enter password: ")
  if read("*") == "YourPassword" then
	print("Correct password")
	break
  else
	print("Incorrect password")
  end
end


EDIT:
Oops, I said Wolvan instead of MysticT.
MysticT #11
Posted 10 June 2012 - 10:42 PM
If you used Wolvan's code, he forgot a "break" so the loop will go forever. Try this:

while true do
  term.clear()
  term.setCursorPos(1, 1)
  write("Enter password: ")
  if read("*") == "YourPassword" then
	print("Correct password")
	break
  else
	print("Incorrect password")
  end
end
That was just an example, and it can be terminated, so that's not the code he's using (or he shouldn't be using it). And I'm not Wolvan :(/>/>
If you did use that code, and you added termination prevention, the only thing you can do is make a new computer and rewrite every program you had. Just kiding :)/>/>, you can place a disk drive and insert a disk with a startup file (it can be blank) and you can access the terminal, then just edit the startup file (on the computer) to make it work.
Traffic_Warden #12
Posted 10 June 2012 - 10:50 PM
Where would this go inside my code?

edit, do you have a simple door lock i could have with that intergrated into it?
MysticT #13
Posted 10 June 2012 - 11:14 PM
You just need to add some things to that code so it does what you want (like opening a door, access the computer, etc.).
Example:

local oldPullEvent = os.pullEvent
os.pullEvent = os.pullEventRaw

local sUser = "YourUsername"
local sPass = "YourPassword"

local function clear()
  term.clear()
  term.setCursorPos(1, 1)
end

while true do
  clear()
  write("User: ")
  local usr = read()
  write("Password: ")
  local pass = read("*")
  if usr == sUser and pass == sPass then
    print("Access granted")
    break
  else
    print("Invalid username/password")
    sleep(1)
  end
end

os.pullEvent = oldPullEvent
It asks for the username and the password, and if they are correct you can use the computer.
Xomsabre #14
Posted 15 June 2012 - 01:48 AM
Where would this go inside my code?

edit, do you have a simple door lock i could have with that intergrated into it?

Here's a basic easy-to-edit password program

os.pullEvent = os.pullEventRaw
function pass()
print("Please Enter Password:")
t = read("*")
if t == "password" then --change password to whatever you want your password to be
print("Correct!") --a simple message telling the user they got the password right
redstone.setOutput("side", true) --change side to the side that your door is on relative to the console
sleep(#) --change # to however long you want the door to be open
redstone.setOutput("side", false) --side is the same as before
--you can add anything else you want the program to do if the password is correct here
else
print("Incorrect Password")
os.reboot() --this will reboot the console if the password was wrong.
end
end
pass()