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

[Comp.][CraftOS v1.5][Security] Login

Started by Vortex, 26 March 2013 - 09:03 PM
Vortex #1
Posted 26 March 2013 - 10:03 PM
Hello guys ! Here's a little program I've made, it's really easy to use and to setup.
The program difficulty is "low-leveled". Almost anyone having screwed around ComputerCraft may know how it works.
Alright, here's the code. Feel free to edit and/or redistribute the program, please leave me credits though. ^_^/>

-- Cabriolaile's login program v1.0
-- Author: Vortex
-- Program type: Computer, 1.5, security
-- Version: 1.0
-- Language used: Lua
while true do
  os.pullEvent = os.pullEventRaw
  term.clear()
  term.setCursorPos(1,1)
  if term.isColor then
	term.setTextColor(colors.blue)
  end
  print("CraftOS Login v1.0 by Vortex")
  if term.isColor then
	term.setTextColor(colors.white)
  end
  print("Please identify yourself.")
  local user="Steve" -- Replace it with your username
  local pass="Password" -- Replace it with your own password.
  term.setCursorPos(3,4)
  write("Username: ")
  term.setCursorPos(3,5)
  write("Password: ")
  term.setCursorPos(5,7)
  write("Username: ")
  input=read()
  if input == user then
	term.setCursorPos(3,4)
	term.clearLine()
	write("Username: "..user)
	term.setCursorPos(5,7)
	term.clearLine()
	write("Password: ")
	input=read("*")
	-- input=read()
	if input == pass then
	  term.setCursorPos(3,5)
	  term.clearLine()
	  write("Password: [hidden]")
	  -- write("Password: "..pass)
	  term.setCursorPos(5,7)
	  if term.isColor then
		term.setTextColor(colors.lime)
	  end
	  write("Password correct! Access granted!")
	  sleep(2)
	  term.setCursorPos(1,1)
	  term.clear()
	else
	  term.setCursorPos(3,7)
	  term.clearLine()
	  if term.isColor then
		term.setTextColor(colors.red)
	  end
	  write("Password not correct. Access denied!")
	  sleep(2)
	end
  else
	term.setCursorPos(5,7)
	term.clearLine()
	if term.isColor then
	  term.setTextColor(colors.red)
	end
	write("User doesn't exist! Access denied!")
	sleep(2)
  end
end

If you notice any error in the code, or things to be upgraded, please report to me, as I will review your change and see if it changes something. Thanks :)/>
Have fun on ComputerCraft !

Take a look at those persons, they helped me making the program safer, and more stablish ! :D/>
SpoilerPersons who helped me fixing the program:
- svdragster
- GravityScore (A little)
- Engineer
svdragster #2
Posted 26 March 2013 - 10:29 PM
Line 42

write("Username: "user)
Should be

write("Username: "..user)
And line 51

write"(Password: [hidden]")
:P/>

When typing something in the program, it crashes and shell crashes, too ^^
Did you even test it?

Edit: The problem is the os.pullEvent().
Just add

os.pullEvent = os.pullEventRaw
at the top of the code, it will prevent ctrl + T, and remove the function.
GravityScore #3
Posted 26 March 2013 - 10:33 PM
Good job!

2 thing to mention on top of the things mentioned above:

1. On the 3rd last line, you spelt doesn't wrong :P/>
2. After getting the password wrong about 250 times, an error will be triggered saying "Stack Overflow". There's a really good tutorial on what this is, why this happens and how to prevent it here.
Vortex #4
Posted 26 March 2013 - 10:50 PM
I see… Sorry about some errors, I wrote what I remembered, and it's possible that there are errors. Repairing :P/>/>
When typing something in the program, it crashes and shell crashes, too ^^
I couldn't figure out why you couldn't write stuff… Sorry :(/>/>
And the shell crash is because the pullEventRaw ignores errors, making the OS crash.

2. After getting the password wrong about 250 times, an error will be triggered saying "Stack Overflow".
Fixed it with a OS reboot instead of the re-booting program, hope it avoids overflows. Thanks for the tutorial by the way :)/>/>

Here's the original program screenshots:
Spoiler



Engineer #5
Posted 27 March 2013 - 03:06 AM
As rebooting is CPU more intensive try a while loop:

while true do
-- code
-- if password is right do then break
end
Vortex #6
Posted 27 March 2013 - 09:01 PM
Hmm. Never though of that, thanks ^-^
Fixing the code with a "while true do" loop

Edit: On the first post, you see Cabriolaile's login program v1.0, the fact is I am also Cabriolaile, but I don't like that username anymore, I still use to use it….