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

[1.3] Security Terminal

Started by Kolpa, 23 March 2012 - 09:59 PM
Kolpa #1
Posted 23 March 2012 - 10:59 PM
So this is my Secure code Lock which instead of writing the password just writes "*"
Code:
Spoiler

os.pullEvent = os.pullEventRaw
password ="changeme"
x = ""
term.clear()
term.setCursorPos(1,1)
term.write("Kolpa s Privacy Terminal")
term.setCursorPos(2,5)
term.write("Password: ")
while true do
id,chr = os.pullEvent()
if id == "char" then
term.write("*")
x = x..chr
end
if id == "key" and chr == 28 then
if x == password then
term.clear()
term.setCursorPos(1,1)
term.write("acces granted")
os.sleep(2)
os.reboot()
else
term.clear()
term.setCursorPos(1,1)
term.write("acces denied")
os.sleep(2)
os.reboot()
end
end
end

Images:
Spoiler[attachment=106:2012-03-24_14.28.39.png]


[attachment=107:2012-03-24_14.28.48.png]

u want pastebin?
Spoileru Realy want pastebin?
Spoileru Realy Realy want pastebin ?
Spoileru get pastebin! :http://pastebin.com/BULn6Tb4
hamish1001 #2
Posted 24 March 2012 - 01:41 AM
cool im putting this in my world
Espen #3
Posted 24 March 2012 - 01:52 AM
@hamish1001:
At the current state of the program, it won't actually work, since the loop doesn't contain a break-condition, i.e. it will run indefinitely.
*derp* Kinda hard to match the end's with their counterparts sometimes with non-indented code. My bad. :(/>/>
But it will reboot in both cases (access denied/granted), so you'd at least have to replace the reboot on "access granted" with a break.

@Kolpa:
I hope you don't mind, just tried to compress the code a little to make it more efficient.

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

clear()
write("Kolpa s Privacy Terminal")
term.setCursorPos(2, 5)
write("Password: ")

while true do
  local pass = read("*")

  if pass == "test" then
	clear()
	write("acces granted")
	os.sleep(2)
	break;  -- Break out of loop.
  else
	clear()
	write("acces denied")
	os.sleep(2)
	os.reboot()
  end
end

Note: Didn't test it ingame, but should work. If it doesn't, give me a holler.
Cheers :)/>/>
Edited on 24 March 2012 - 12:59 AM
Zer0t3ch #4
Posted 24 March 2012 - 02:10 AM
@hamish1001:
At the current state of the program, it won't actually work, since the loop doesn't contain a break-condition, i.e. it will run indefinitely.
*derp* Kinda hard to match the end's with their counterparts sometimes with non-indented code. My bad. :(/>/>
But it will reboot in both cases (access denied/granted), so you'd at least have to replace the reboot on "access granted" with a break.

@Kolpa:
I hope you don't mind, just tried to compress the code a little to make it more efficient.

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

clear()
write("Kolpa s Privacy Terminal")
term.setCursorPos(2, 5)
write("Password: ")

while true do
  local pass = read("*")

  if pass == "test" then
	clear()
	write("acces granted")
	os.sleep(2)
	break;  -- Break out of loop.
  else
	clear()
	write("acces denied")
	os.sleep(2)
	os.reboot()
  end
end

Note: Didn't test it ingame, but should work. If it doesn't, give me a holler.
Cheers :)/>/>

You're edit looks nice. Has anyone figured out a way to make programs non-terminate-able? (not a word, I know) Without editing the actual OS?
coolblockj #5
Posted 24 March 2012 - 02:25 AM
@hamish1001:
At the current state of the program, it won't actually work, since the loop doesn't contain a break-condition, i.e. it will run indefinitely.
*derp* Kinda hard to match the end's with their counterparts sometimes with non-indented code. My bad. :(/>/>
But it will reboot in both cases (access denied/granted), so you'd at least have to replace the reboot on "access granted" with a break.

@Kolpa:
I hope you don't mind, just tried to compress the code a little to make it more efficient.

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

clear()
write("Kolpa s Privacy Terminal")
term.setCursorPos(2, 5)
write("Password: ")

while true do
  local pass = read("*")

  if pass == "test" then
	clear()
	write("acces granted")
	os.sleep(2)
	break;  -- Break out of loop.
  else
	clear()
	write("acces denied")
	os.sleep(2)
	os.reboot()
  end
end

Note: Didn't test it ingame, but should work. If it doesn't, give me a holler.
Cheers :)/>/>

You're edit looks nice. Has anyone figured out a way to make programs non-terminate-able? (not a word, I know) Without editing the actual OS?
You can set os.pullEvent to os.pullEventRaw, like this :

nos.pullEvent = os.pullEvent
os.pullEvent = os.pullEventRaw
Yourcodehere
os.pullEvent = nos.pullEvent --Resets it back to normal after you're done.
Espen #6
Posted 24 March 2012 - 02:26 AM
Whoops, got ninja'd. Just Ignore this now pointless post.^^
Edited on 24 March 2012 - 01:27 AM
Zer0t3ch #7
Posted 24 March 2012 - 02:31 AM
Cool! (BTW, your post is f'ed up)
Zer0t3ch #8
Posted 24 March 2012 - 02:42 AM
@hamish1001:
At the current state of the program, it won't actually work, since the loop doesn't contain a break-condition, i.e. it will run indefinitely.
*derp* Kinda hard to match the end's with their counterparts sometimes with non-indented code. My bad. :(/>/>
But it will reboot in both cases (access denied/granted), so you'd at least have to replace the reboot on "access granted" with a break.

@Kolpa:
I hope you don't mind, just tried to compress the code a little to make it more efficient.

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

clear()
write("Kolpa s Privacy Terminal")
term.setCursorPos(2, 5)
write("Password: ")

while true do
  local pass = read("*")

  if pass == "test" then
	clear()
	write("acces granted")
	os.sleep(2)
	break;  -- Break out of loop.
  else
	clear()
	write("acces denied")
	os.sleep(2)
	os.reboot()
  end
end

Note: Didn't test it ingame, but should work. If it doesn't, give me a holler.
Cheers :)/>/>

You're edit looks nice. Has anyone figured out a way to make programs non-terminate-able? (not a word, I know) Without editing the actual OS?
You can set os.pullEvent to os.pullEventRaw, like this :

nos.pullEvent = os.pullEvent
os.pullEvent = os.pullEventRaw
Yourcodehere
os.pullEvent = nos.pullEvent --Resets it back to normal after you're done.
I tried out that code as you said it, exactly, it crashes and shuts down but I managed to print screen it.

http://www.zer0t3ch....03/Untitled.png
coolblockj #9
Posted 24 March 2012 - 04:18 AM
@hamish1001:
At the current state of the program, it won't actually work, since the loop doesn't contain a break-condition, i.e. it will run indefinitely.
*derp* Kinda hard to match the end's with their counterparts sometimes with non-indented code. My bad. :(/>/>
But it will reboot in both cases (access denied/granted), so you'd at least have to replace the reboot on "access granted" with a break.

@Kolpa:
I hope you don't mind, just tried to compress the code a little to make it more efficient.

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

clear()
write("Kolpa s Privacy Terminal")
term.setCursorPos(2, 5)
write("Password: ")

while true do
  local pass = read("*")

  if pass == "test" then
	clear()
	write("acces granted")
	os.sleep(2)
	break;  -- Break out of loop.
  else
	clear()
	write("acces denied")
	os.sleep(2)
	os.reboot()
  end
end

Note: Didn't test it ingame, but should work. If it doesn't, give me a holler.
Cheers :)/>/>

You're edit looks nice. Has anyone figured out a way to make programs non-terminate-able? (not a word, I know) Without editing the actual OS?
You can set os.pullEvent to os.pullEventRaw, like this :

nos.pullEvent = os.pullEvent
os.pullEvent = os.pullEventRaw
Yourcodehere
os.pullEvent = nos.pullEvent --Resets it back to normal after you're done.
I tried out that code as you said it, exactly, it crashes and shuts down but I managed to print screen it.

http://www.zer0t3ch....03/Untitled.png
Could you take a pic of the code, or put it down exactly on here?
This way i'll be able to help more accurately.
Also, are you using tekkit? I've heard there might be a few bugs in tekkit with it.
Zer0t3ch #10
Posted 24 March 2012 - 04:44 AM
Yes I am using tekkit



while true do
pullEvent = os.pullEvent()
os.pullEvent = os.pullEventRaw()
os.pullEvent = pullEvent
end
After key press it instantly crashes, I have tried multiple variations, with and without parens, and this is what it is now. Any ideas?
Espen #11
Posted 24 March 2012 - 11:58 AM
@Zer0t3ch
os.pullEvent returns the function itself, os.pullEvent() executes the function and returns the results of that.
Also the code to backup os.pullEvent is supposed to be executed at the very beginning and end of your program, outside of any other parts.
Like this:

local oldPullEvent = os.pullEvent  -- Creates a copy of the function pullEvent under the local variable oldPullEvent
os.pullEvent = pullEventRaw  -- Overwrite the global function os.pullEvent with os.pullEventRaw

-- From now on every call to os.pullEvent() is essentially the same as a call to os.pullEventRaw().
-- This effectively prevents program termination, because os.pullEventRaw does not stop the program when the 'terminate' event occurs.

-- After you are done with your program we restore the global function os.pullEvent again with the backup we made at the beginning.
os.pullEvent = oldPullEvent
Kolpa #12
Posted 24 March 2012 - 01:21 PM
@hamish1001:
At the current state of the program, it won't actually work, since the loop doesn't contain a break-condition, i.e. it will run indefinitely.
*derp* Kinda hard to match the end's with their counterparts sometimes with non-indented code. My bad. :(/>/>
But it will reboot in both cases (access denied/granted), so you'd at least have to replace the reboot on "access granted" with a break.

@Kolpa:
I hope you don't mind, just tried to compress the code a little to make it more efficient.

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

clear()
write("Kolpa s Privacy Terminal")
term.setCursorPos(2, 5)
write("Password: ")

while true do
  local pass = read("*")

  if pass == "test" then
	clear()
	write("acces granted")
	os.sleep(2)
	break;  -- Break out of loop.
  else
	clear()
	write("acces denied")
	os.sleep(2)
	os.reboot()
  end
end

Note: Didn't test it ingame, but should work. If it doesn't, give me a holler.
Cheers :)/>/>

i actualy did the code with the reboot just to show off what u can do,
anyway thanks for the edit had to go and coudnt describe the post anymore will edit that
coolblockj #13
Posted 24 March 2012 - 08:33 PM
@Zer0t3ch
os.pullEvent returns the function itself, os.pullEvent() executes the function and returns the results of that.
Also the code to backup os.pullEvent is supposed to be executed at the very beginning and end of your program, outside of any other parts.
Like this:

local oldPullEvent = os.pullEvent  -- Creates a copy of the function pullEvent under the local variable oldPullEvent
os.pullEvent = pullEventRaw  -- Overwrite the global function os.pullEvent with os.pullEventRaw

-- From now on every call to os.pullEvent() is essentially the same as a call to os.pullEventRaw().
-- This effectively prevents program termination, because os.pullEventRaw does not stop the program when the 'terminate' event occurs.

-- After you are done with your program we restore the global function os.pullEvent again with the backup we made at the beginning.
os.pullEvent = oldPullEvent
You got to it first :(/>/>
Robd #14
Posted 04 April 2012 - 02:23 AM
Hmm… I've done something very similar with some of my own consoles (only I don't use the stars). Might I suggest that you make an event for the backspace key so that you don't have to reboot if you mis-type a key?