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

How to have a password protected computer

Started by William836, 21 November 2012 - 06:08 AM
William836 #1
Posted 21 November 2012 - 07:08 AM
Hello, this is how to make a password protected computer! :(/>/>

First you will want to type "edit startup" and then enter the code below to make it work!


while true do
term.clear()
term.setCursorPos (1, 1)
print ("Input Password")
input = read ("*")
if input == "your password" then
print ("Access Granted")
error()
else
print ("Incorrect")
sleep(1)
os.shutdown()
end
end

PS. where it says "your password" that's where your password goes!
If you want to download the code I will attach the file.
bootsy904 #2
Posted 23 November 2012 - 10:08 AM
Hi im new to progaming but "error()" i beileve is a functuion that you wrote. but if i may sugesst something. it would be to add an "os.pullEvent = os.pullEventRaw" so you can prevent people ctrl t out of the program and to make it so it wont do any thing till the correct pass word is put in.






os.pullEvent=os.pullEventRaw—–to stop the ctrl t
while true do
term.clear()
term.setCursorPos (1, 1)
print ("Input Password")
input = read ("*")
if input == "your password" then
print ("Access Granted")
error()—right here could you explain?
else
print ("Incorrect")
sleep(1)
os.shutdown()
end
end
Matrixrider #3
Posted 29 January 2013 - 05:01 PM
Instead of having to do

Term.clear()
Term.setCursorPos(1,1)

You can just do

Shell.run("clear")

It clears the screen and sets the cursor position to 1,1
theoriginalbit #4
Posted 29 January 2013 - 05:26 PM
Hi im new to progaming but "error()" i beileve is a functuion that you wrote.
Nope it is not, it is a system function. I suggest reading this http://www.lua.org/pil/

but if i may sugesst something. it would be to add an "os.pullEvent = os.pullEventRaw" so you can prevent people ctrl t out of the program.
Not the best solution to stopping this. Yes it works. But it's not an ideal solution, there are much better ways of doing this without overriding a function with another.

You can just do
Shell.run("clear")
OR don't rely on an external program to clear the screen and just do it the way you want to. What happens if later thy change how the clear program works? Also it is possible (unlikely, but possible) that using shell.run("clear") causes more problems than using term.clear() term.setCursorPos(1,1)
Shnupbups #5
Posted 29 January 2013 - 05:45 PM
Note that almost everyone here, excluding BIT and myself, has 2 or less posts.

More professional code:

local function clear()
  term.clear()
  term.setCursorPos(1,1)
end
os.pullEvent = os.pullEventRaw
local tries = 3
while tries > 0 do
  clear()
  print("A password is required to access this computer.")
  write("Password: ")
  local input = read("*")
  if input == "YourPasswordHere" then
	print("Password Accepted. Access Granted.")
	sleep(1)
	clear()
	shell.run("shell")
  else
	print("Password Rejected. Access Denied.")
	tries = tries - 1
	print(tries.." tries remaining.")
	sleep(1)
  end
end
local sec = 10
while sec ~= 0 do
  clear()
  print("Please try again in "..sec.." seconds.")
  sec = sec - 1
  sleep(1)
end
os.reboot()
theoriginalbit #6
Posted 29 January 2013 - 05:57 PM
Note that almost everyone here, excluding BIT and myself, has 2 or less posts.
Yes I do notice that, and its what I don't like about it. n00bs telling n00bs they are wrong and what to do while making similar n00b mistakes, hence why I posted, to teach so next time they will hopefully recommend something better.

Way Off-Topic: your signature, it is possible to have 3 whole URL's in your signature, put the link in using the link button, click ok, then highlight the link (except a char at the front and end) type what you want it to say, then remove the chars. like so
anonimo182 #7
Posted 30 January 2013 - 10:25 AM
Note that almost everyone here, excluding BIT and myself, has 2 or less posts.

More professional code:

local function clear()
  term.clear()
  term.setCursorPos(1,1)
end
os.pullEvent = os.pullEventRaw
local tries = 3
while tries > 0 do
  clear()
  print("A password is required to access this computer.")
  write("Password: ")
  local input = read("*")
  if input == "YourPasswordHere" then
	print("Password Accepted. Access Granted.")
	sleep(1)
	clear()
	shell.run("shell")
  else
	print("Password Rejected. Access Denied.")
	tries = tries - 1
	print(tries.." tries remaining.")
	sleep(1)
  end
end
local sec = 10
while sec ~= 0 do
  clear()
  print("Please try again in "..sec.." seconds.")
  sec = sec - 1
  sleep(1)
end
os.reboot()
The part that make shell.run("shell") can be just a return, as it exists the program to the top shell


Yes I do notice that, and its what I don't like about it. n00bs telling n00bs they are wrong and what to do while making similar n00b mistakes, hence why I posted, to teach so next time they will hopefully recommend something better.
Agree
theoriginalbit #8
Posted 30 January 2013 - 12:06 PM
The part that make shell.run("shell") can be just a return, as it exists the program to the top shell
Good pickup, didn't see that one
Orwell #9
Posted 30 January 2013 - 12:15 PM
Yes I do notice that, and its what I don't like about it. n00bs telling n00bs they are wrong and what to do while making similar n00b mistakes, hence why I posted, to teach so next time they will hopefully recommend something better.
I think it's a bit harsh. it could be sort of true for Matrixrider, but bootsy904 really said he was suggesting something and his post was quite polite. Also, the number of posts is not a valid reference for skill. And besides that, everyone has the right to help each other. You can't really judge when you're not skilled enough to give decent help… It needs to grow.
spyman68 #10
Posted 17 March 2013 - 12:36 PM
First of all, how is this an API? Second of all, don't go posting your first code here which everyone has made, it just clogs up the forum
theoriginalbit #11
Posted 17 March 2013 - 03:44 PM
First of all, how is this an API? Second of all, don't go posting your first code here which everyone has made, it just clogs up the forum
2 things
#1: Don't be a necro.
#2: Read this thread to see why people should be encouraged not discouraged from posting their code!
Lyqyd #12
Posted 17 March 2013 - 03:51 PM
First of all, how is this an API? Second of all, don't go posting your first code here which everyone has made, it just clogs up the forum

You know what clogs up the forum more than people posting code?

People rudely telling other people not to post their code. People bumping month-old (or more!) topics and not adding content. People who don't think before they post. Don't backseat moderate. If you see a post that you think doesn't belong, don't reply to it, report it.

You too on the report-don't-reply thing, TheOriginalBIT. ;)/>

Locked.