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

BouTech Login System

Started by boudragon, 08 July 2013 - 07:30 AM
boudragon #1
Posted 08 July 2013 - 09:30 AM
Alright so after about a week of working on this I THINK it's done (for now but more is planned). It may be a bit sloppy but it works. You are all welcome to comment, suggest or even help clean this beast up a bit. Welcome to my login system! Let me take a minute to explain it's features.

LOGIN FEATURES
  • Matches username and password to allow access to a program that requires credentials. (username is a file in users/[username] and password is a line of text within said file)
  • Ignores blank entries for both username and password and after several failed attempts will kick you back to the main menu.
  • Will ignore unknown usernames.
  • Will lock down an account after three failed attempts to log in with an invalid password. (locked accounts are moved from users folder to pending folder and renamed to a random number for safe keeping. Will also check to ensure the random file name is not already in use)
  • Admin override feature allows the system owner to enter the system shell without risk of major security breaches by utilizing a random password algorithm to generate new passwords upon each override request. (Current algorithm is (rnd + 11) * 83 where rnd = a random number generated by the system and displayed as an override code. Admin override login name is currently adminovrride)
  • Reads the user account and applies an access level based on what the Admin has set for that user. (Currently only two access levels, admin and user, with more able to be added)
CREATE ACCOUNT FEATURES
  • Allows user to create an account by providing a username and password. The system then puts the information in a randomly generated file in the pending folder for safe keeping and admin approval at a later time. (Will check to ensure random file name is not already in use)
  • Ignores blank entries for both username and password and after several failed attempts will kick you back to the main menu.
  • Will ignore usernames already in use.
  • Will disallow the creation of an account using the same login of the admin override feature.
  • Matches password and confirm password to ensure the user selected a proper password for themselves.
GENERAL FEATURES
  • Ctrl-T is disallowed.
  • Max input length is currently set to 12 but can be changed.
  • Easy to modify to suit your needs.
  • Self-sustained program in itself to allow easy integration to your system and it's other programs.
  • Basic design to allow users of both basic and advanced computers to use this login system.
REQUIREMENTS
  • Two directories need to be pre-made prior to running. These directories are [users] and [pending] without the brackets and must be placed in the root of the system.
SCREENSHOTS
SpoilerMain Screen Admin Override Account Creation Random File Created Inside Random File

PLANNED FEATURES
  • Ability to determine whether the user is an admin or user. (Possibly other access levels as well)
  • Integration into an overall OS where the system boots and does a system check. (memory, file structure etc.) If the check fails it will initiate a system restore sequence from disk to restore the system to it's previous state including any back-up files saved.
  • Checks to see if the "pending" and the "users" directory exists. If not the program will create them.
Without further hesitation… here it is! Please keep in mind this is only my SECOND program released so don't be too critical ok? :)/> Enjoy!

Spoiler

	local function readN(len, replaceChar)
	  len = len or 12
	  local input=""
	  local key = 0
	  term.setCursorBlink(true)
	  repeat
		local e,p1 = os.pullEvent()
		if e=="char" then
		  if #input < len then
			input = input .. p1
			term.write(replaceChar or p1)
		  end
		elseif e=="key" and p1==keys.backspace and #input > 0 then
		  input = input:sub(1,#input-1)
		  local x,y = term.getCursorPos()
		  term.setCursorPos(x-1,y)
		  term.write(" ")
		  term.setCursorPos(x-1,y)
		end
	  until p1==keys.enter
	  term.setCursorBlink(false)
	  return input
	end
	
	sid = 0
	lockdown = 0
	actc = ""
	actpw = ""
	actpc = ""
	userlog = ""
	userpas = ""
	puselog = ""
	prog = 0
	
	function clear()
	term.clear()
	term.setCursorPos(1,1)
	end
	
	function menu(id, text)
	  if sid == id then
		write">> "
	  else
		write"   "
	  end
	  print(text)
	end
	
	clear()
	while prog == 0 do
	os.pullEvent = os.pullEventRaw
	rep1 = 0
	rep2 = 0
	rep3 = 0
	rep4 = 0
	rep5 = 0
	rep6 = 0
	ioerror = 0
	term.setCursorPos(1, 12)
	term.clearLine()
	term.setCursorPos(1, 13)
	term.clearLine()
	term.setCursorPos(1, 14)
	term.clearLine()
	term.setCursorPos(1, 15)
	term.clearLine()
	term.setCursorPos(1, 16)
	term.clearLine()
	term.setCursorPos(1, 17)
	term.clearLine()
	term.setCursorPos(1,1)
	print("|################################################|")
	print("|			  BOUTECH SYSTEM LOGIN			  |")
	print("|				OS Version : 1.3				|")
	print("|################################################|")
	term.setCursorPos(13,7)
	print("|------------------------|")
	term.setCursorPos(13,8)
	print("|						|")
	term.setCursorPos(13,9)
	print("|						|")
	term.setCursorPos(13,10)
	print("|						|")
	term.setCursorPos(13,11)
	print("|------------------------|")
	term.setCursorPos(16,8)
	menu(0, "Login")
	term.setCursorPos(16,9)
	menu(1, "Create Account")
	term.setCursorPos(16,10)
	menu(2, "Shutdown")
	event, key = os.pullEvent("key")
	
	if key == 200 then
	  if sid == 0 then
		sid = sid+2
	  elseif sid == 1 then
		sid = sid-1
	  elseif sid == 2 then
		sid = sid-1
	  end
	elseif key == 208 then
	  if sid == 2 then
		sid = sid-2
	  elseif sid == 1 then
		sid = sid+1
	  elseif sid == 0 then
		sid = sid+1
	  end
	elseif key == 28 then
	  if sid == 0 then
		term.setCursorPos(13, 12)
		print("|   Enter Credentials.   |")
		term.setCursorPos(13, 13)
		print("|						|")
		term.setCursorPos(13, 14)
		print("|						|")
		term.setCursorPos(13, 15)
		print("|						|")
		term.setCursorPos(13, 16)
		print("|						|")
		term.setCursorPos(13, 17)
		print("|------------------------|")
	  
		while rep5 == 0 do
		  term.setCursorPos(1, 14)
		  term.clearLine()
		  term.setCursorPos(1, 16)
		  term.clearLine()
		  term.setCursorPos(13, 16)
		  print("|						|")
		  term.setCursorPos(13, 14)
		  print("|						|")
		  term.setCursorPos(15, 14)
		  write("Username: ")
		  userlog = readN()
		  if userlog == "adminovrride" then
			rnd = math.random(100, 500)
			term.setCursorPos(1, 18)
			term.clearLine()
			term.setCursorPos (17, 18)
			print("Override Code: ".. rnd)
			apass = tostring((rnd + 11) * 83)
			term.setCursorPos(1, 16)
			term.clearLine()
			term.setCursorPos(13, 16)
			print("|						|")
			term.setCursorPos(15, 16)
			write("Password: ")
			ovrpass = readN(12, "*")
			if ovrpass == apass then
			  term.setCursorPos(1, 18)
			  term.clearLine()
			  term.setCursorPos(15, 18)
			  print("Override Successful...")
			  sleep(3)
			  term.clear()
			  term.setCursorPos(1, 1)
			  rep5 = rep5+1
			  rep6 = rep6+1
			  prog = prog+1
			else
			  term.setCursorPos(1, 18)
			  term.clearLine()
			  term.setCursorPos(15, 18)
			  print("  Override Failed...")
			  sleep(1)
			  rep5 = rep5+1
			  rep6 = rep6+1
			  sid = 0
			end
		  else	
			if userlog == "" then
			  term.setCursorPos(1, 18)
			  term.clearLine()
			  term.setCursorPos(18, 18)
			  print("Invalid Username")
			  sleep(1)
			  ioerror = ioerror+1
			  if ioerror == 3 then
				rep5 = rep5+1
				rep6 = rep6+1
				sid = 0
			  else
			  end
			else
			  ioerror = 0
			  ulog = fs.exists("users/".. userlog)
			  if ulog == true then
				term.setCursorPos(1, 16)
				term.clearLine()
				term.setCursorPos(13, 16)
				print("|						|")
				term.setCursorPos(15, 16)
				write("Password: ")
				userpas = readN(12, "*")
				if userpas == "" then
				  term.setCursorPos(1, 18)
				  term.clearLine()
				  term.setCursorPos(15, 18)
				  print("Invalid Password Entry")
				  sleep(1)
				  ioerror = ioerror+1
				  term.setCursorPos(1, 18)
				  term.clearLine()
				  if ioerror == 3 then
					rep5 = rep5+1
					sid = 0
				  else
				  end
				else
				  ulog = io.open("users/".. userlog, "r") or nil
				  pass = ulog and ulog:read()
				  ulog:close()
				  if (pass and pass==userpas) then
					term.setCursorPos(1, 18)
					term.clearLine()
					term.setCursorPos(16, 18)
					print("  Login Success...")
					rep5 = rep5+1
					rep6 = rep6+1
					sid = 0
					sleep(2)
					--Put your shell.run([PROGRAM]) here to move into the system you had locked by this program.
				  else
					if lockdown < 2 then
					  term.setCursorPos(1, 18)
					  term.clearLine()
					  term.setCursorPos(16, 18)
					  print("   Wrong Password")
					  sleep(1)
					  if userlog == puselog then
						lockdown = lockdown+1				  
					  else
						lockdown = 0
						puselog = userlog
						lockdown = lockdown+1
					  end
					else
					  while rep6 == 0 do
						term.setCursorPos(15, 18)
						rnd = tostring(math.random(101, 999))
						if not fs.exists("pending/".. rnd) then
						  fs.move("users/".. userlog, "pending/".. rnd)
						  term.setCursorPos(1, 18)
						  term.clearLine()
						  term.setCursorPos(15, 18)
						  print(" Lockdown Ref #: "..rnd)
						  sleep(1)
						  ulog = fs.open("pending/".. rnd, "a")
						  ulog.writeLine("Username: ".. userlog)
						  ulog.close()
						  rep6 = rep6+1
						  rep5 = rep5+1
						  sid = 0
						else
						end
					  end
					end
				  end
				end
			  else
				term.setCursorPos(14, 18)
				print("  Bad/Unknown Username")
				sleep(1)
			  end
			end
		  end
		end
	  elseif sid == 1 then
		term.setCursorPos(13, 12)
		print("|  Submit Account Info.  |")
		term.setCursorPos(13, 13)
		print("|						|")
		term.setCursorPos(13, 14)
		print("|						|")
		term.setCursorPos(13, 15)
		print("|						|")
		term.setCursorPos(13, 16)
		print("|						|")
		term.setCursorPos(13, 17)
		print("|------------------------|")
		  
		while rep1 == 0 do
		  term.setCursorPos(1, 14)
		  term.clearLine()
		  term.setCursorPos(13, 14)
		  print("|						|")
		  term.setCursorPos(15, 14)
		  write("Username: ")
		  input = readN()
		  actc = input
		  actex = fs.exists("users/".. actc)
		  if input == "adminovrride" then
			term.setCursorPos(1, 18)
			term.clearLine()
			term.setCursorPos(18, 18)
			print("Invalid Username")
			sleep(1)
			ioerror = ioerror+1
			if ioerror == 3 then
			  rep1 = 1
			  rep2 = 1
			  rep3 = 1
			  sid = 0
			else
			end
		  else
			if input == "" then
			  term.setCursorPos(1, 18)
			  term.clearLine()
			  term.setCursorPos(18, 18)
			  print("Invalid Username")
			  sleep(1)
			  ioerror = ioerror+1
			  if ioerror == 3 then
				rep1 = 1
				rep2 = 1
				rep3 = 1
				sid = 0
			  else
			  end
			elseif actex == true then
			  term.setCursorPos(1, 18)
			  term.clearLine()
			  term.setCursorPos(15, 18)
			  print (" Username Unavailable")
			  sleep(1)
			else
			  ioerror = 0
			  rep1 = 1
			end
		  end
		end
	  
		while rep2 == 0 do
		  while rep3 == 0 do
			term.setCursorPos(15, 15)
			write("Password: ")
			input = readN(12, "*")
			if input == "" then
			  term.setCursorPos(1, 18)
			  term.clearLine()
			  term.setCursorPos(15, 18)
			  print("Invalid Password Entry")
			  sleep(1)
			  ioerror = ioerror+1
			  if ioerror == 3 then
				rep1 = 1
				rep2 = 1
				rep3 = 1
			  else
			  end
			else
			  ioerror = 0
			  actpw = input
			  rep3 = 1
			  rep2 = 1
			end
		  end
		
		  term.setCursorPos(13, 16)
		  print("|						|")
		  term.setCursorPos(15, 16)
		  write("Confirm : ")
		  input = readN(12, "*")
		  actpc = input
		  if (actpc) == (actpw) then
			while rep4 == 0 do
			  rnd = tostring(math.random(1011, 9999))
			  if not fs.exists("pending/".. rnd) then
				file = fs.open("pending/".. rnd, "w")
				file.writeLine(actc)
				file.writeLine(actpw)
				file.close()
				rep4 = rep4+1
			  else
			  end
			end
			term.setCursorPos(1, 18)
			term.clearLine()
			term.setCursorPos(13, 18)
			print("  Pending... Ref #: ", rnd)
			sleep(1)
			ioerror = 0
			rep2 = 1
			sid = 0
		  else
			term.setCursorPos(1, 18)
			term.clearLine()
			term.setCursorPos(15, 18)
			print("Password Doesn't Match")
			sleep(1)
			rep2 = 0
			ioerror = ioerror+1
			if ioerror == 3 then
			  rep1 = 1
			  rep2 = 1
			  rep3 = 1
			else
			end
		  end
		end
	  
	  elseif sid == 2 then
		term.setCursorPos(13,14)
		print("|########################|")
		term.setCursorPos(13,15)
		print("# SYSTEM SHUTTING DOWN!! #")
		term.setCursorPos(13,16)
		print("|########################|")
		sleep(3)
		os.shutdown()
		end
	  end
	end


PASTEBIN
  • Pastebin get tK3ikweu (You can also get this code (Ctrl-T function is allowed) from Pastebin)
Zudo #2
Posted 08 July 2013 - 02:08 PM
Screenies?
boudragon #3
Posted 08 July 2013 - 03:02 PM
I didn't post any cause it's a fairly simple menu… but I can in a sec…
boudragon #4
Posted 08 July 2013 - 03:22 PM
Screenshots up… enjoy :)/>
Thib0704 #5
Posted 08 July 2013 - 04:07 PM
I seem to get an error when I create an account : System :372: attempt to index ?( a nil value ).
But the GUI look's quite nice
Thib0704 #6
Posted 08 July 2013 - 04:10 PM
I seem to get an error :
system : 372 : attempt to index ? ( a nil value )
But the GUI look's nice.

EDIT : damn my post didnt show up
boudragon #7
Posted 08 July 2013 - 04:11 PM
did you add two folders into your root? you need to mkdir users and mkdir pending
Zudo #8
Posted 08 July 2013 - 04:14 PM
The GUI looks nice!
boudragon #9
Posted 08 July 2013 - 04:22 PM
Thank you :)/> It's just something I threw together really…
boudragon #10
Posted 14 July 2013 - 11:21 AM
New version uploaded to Pastebin. Check it out and let me know what you think :)/>
boudragon #11
Posted 29 September 2013 - 10:03 AM
Know it's been a while since my last updates or post but I cleaned this up a little and posted the new version on Pastebin. Wanted to know if anyone actually likes and or uses this and would like to see it improve further. Suggestions and comments are all welcome.
Kamefrede #12
Posted 29 September 2013 - 10:22 AM
This is actually a good program, i like, but could u make a nyan cat( rainbow) version of this , i really like rainbows hehe
boudragon #13
Posted 29 September 2013 - 10:33 AM
LOL I've never actually seen what you are talking about so I would have to look it up… plus I programmed it using the basic computer so there is no color scheme but it obviously can be done. Just takes some time and effort :)/> You are more than welcome to play around with the code just be sure to give credit where due :)/>
willwac #14
Posted 30 September 2013 - 07:01 PM
I like it a lot, it reminds me of my DuoStep Login system, but better!
I'd like to help you make this.
boudragon #15
Posted 30 September 2013 - 11:12 PM
I like it a lot, it reminds me of my DuoStep Login system, but better!
I'd like to help you make this.

As far as the login aside from maybe cleaning it up and what not it works perfect. The rest is a bit sketchy as far as implementing it into an actual OS or other program because everyone's needs are different. But I am open to ideas just inbox me! :)/>
boudragon #16
Posted 18 October 2013 - 10:24 PM
Fixed a few minor details with login system. System manager is coming along nicely and with the help of Sir Lyqyd may even become a client/host control panel for devices and such. If anyone is interested in this let me know… I need some motivation! :-p
Dragon53535 #17
Posted 18 October 2013 - 10:43 PM
Hehe, this seems nice, but i would recommend using some encryption in the passwords if you haven't already like sha256 or something, other than that, this works pretty much like my own code i wrote a few weeks ago.
boudragon #18
Posted 18 October 2013 - 10:54 PM
well considering the program will not allow ANY form of unauthorized program termination plus it's split between multiple files rather than just one big program… it should be relatively safe. I disabled floppy disk startup files from loading on my server for just that reason… security. I can still look into it though and I appreciate the idea :)/>
Dragon53535 #19
Posted 18 October 2013 - 11:00 PM
i'm actually curious how you got it to place the files under a random name inside a directory, and then still knowing which file is which user.
boudragon #20
Posted 19 October 2013 - 10:16 AM
Well it's simple really. I just told it to randomly pick a number between A and B and then check if a file with that number already exists. If it does it tries again if it doesn't it creates the file and puts the name and password in that file. Mind you its just pending account at this point becuase after all this is a secure system so it wouldn't make sense to allow instant access. Plus a user access level has to be applied by an admin anyways.

Once the System manager is complete any admin will be able to go in and approve pending or locked files and change user access levels. Right now the only way to do so is manually either prior to running the login system or using the adminovrride login name which I LOVE the access password for that ;-) basically it generates a 3 digit number which you then must know the proper algorithm to get the password. in case you didn't find it… its (RND+11)*83 = password. RND is the override code it generates. Check it out when you get a chance :)/>
Dragon53535 #21
Posted 19 October 2013 - 02:46 PM
Nice, I had a similar system on mine for the admin authentication for new accounts, basically i just put their usernames inside a file, and then read the file to accept or decline.
oh, and i would try and implement some encryption if you haven't already.
boudragon #22
Posted 19 October 2013 - 04:46 PM
For now it's safe enough. I don't have anyone untrustworthy on my server yet so it's not a big deal… but I plan on making it even more secure. Like maybe setting up an authentication certificate or something. Maybe make it check the users IP address to ensure the right player is logging into the right account.
Dragon53535 #23
Posted 19 October 2013 - 04:48 PM
The ip address would probably be a bad thing, as it can promote hackers to hack into them.
boudragon #24
Posted 19 October 2013 - 05:03 PM
Not really… what I mean is when you create an account it would be linked to something personaly to that user like an IP address or something similar to where they can only use THAT computer to log into their ComputerCraft account. You can also set multiple IPs so that the person can log in from different locations as set by the admins. I dunno… I'll think about it ;)/>
Dragon53535 #25
Posted 19 October 2013 - 05:46 PM
What you could do is have an authentication server, and then have a "login" program on startup on a disk that is connected to a login computer that then logs in with a code on the disk, so that the computer doesn't have a trace of the login.
boudragon #26
Posted 19 October 2013 - 06:36 PM
Well that's just it… the login and system manager will be server-side once it's all done. The client computer will house NO files other than a direct connect access to the login system.
Dragon53535 #27
Posted 19 October 2013 - 07:38 PM
Then use a floppy for authentication, so that it sends the code straight to the server.
deeb332 #28
Posted 19 October 2013 - 09:27 PM
I am kinda new to computercraft. Soooo in this file how would I download it to pastebin? And would I edit the startup? Please help!
Dragon53535 #29
Posted 19 October 2013 - 09:54 PM
Deeb you are going to have to be more specific
boudragon #30
Posted 19 October 2013 - 10:15 PM
You could always use my Pastebin Download Lite ;)/> Makes it a LOT easier to download files from Pastebin. But even so you have to get it the same way you get any other files… type:

pastebin get [Pastebin Code] [File Name]

Make sure your HTTP is enabled otherwise it won't work.

You don't really HAVE to make a startup file to use it… but it makes sense that you would want this login program to pop up right away.
deeb332 #31
Posted 22 October 2013 - 09:39 PM
I am kinda new to computercraft. Soooo in this file how would I download it to pastebin? And would I edit the startup? Please help!
Sorry! I wasn't thinking when I wrote this post! I got it! Thanks anyways!
boudragon #32
Posted 22 October 2013 - 10:07 PM
Cool deal :)/> Let me know what you think of it ;)/>
slugy12345 #33
Posted 23 October 2013 - 06:32 AM
I made something a bit like this where you log in to a computer and I'm trying to get you to beable to make a selectable password with the first time you log in. I called the program I made BoneWare V.0.1 Alpha. I'm looking to make a entire operating system and sell it to people on servers.
boudragon #34
Posted 23 October 2013 - 07:10 AM
That's the idea so-to-speak with this… I am making my system in parts so that it's easy to manipulate as well as make it universal so if someone wants the login but not the system manager or visa versa they can do so and edit it with ease. In fact the system manager is being built in functions (sections) so that if you want to edit a particular menu, message or feature it will be much easier to do so. I should have done that with the login system but oh well :)/> maybe when I feel up to cleaning up my code I will :-p Did you try this one out?
Angel_Code #35
Posted 29 November 2013 - 01:08 AM
ok there seems to be a problem

i have done Pastebin get tK3ikweu and set its name to ccl i then
launched it
created a username and password
but when i hit login and enter my username it says Bad/unknown username
i checked the files its saving the information in the pending folder but nothing in the users folder
if someone could let me know how to fix this id be grateful
cal12787 #36
Posted 09 January 2014 - 10:11 AM
How can i make different user run different programe once loged in, i.e admins run program 1, and users run program 2.

Also i manage to add users by creating a file with there name and password inside, but what is the correct way to do this i.e with adminovrride im unsure, im very new to computer craft and have being trying and learning what i can but im just boggeled at the moment
CoLDarkness #37
Posted 10 January 2014 - 02:01 PM
One-way encryption used on this would create something neat,

or you can come up with other methods that might be more secure.
boudragon #38
Posted 23 January 2014 - 12:56 PM
Sorry been gone a long time… currently there is no way to approve or deny created users. It's a sort of placeholder for the system manager in it's entirety. For now you have to manually add the file in the users folder as such:

Filename = Username
Line 1 = password
Line 2 = access level (either "a" for admin or "u" for user without quotes)

Hope this helps :)/>
Coderforlife #39
Posted 23 January 2014 - 04:04 PM
This looks quite fancy :)/> Good job!
boudragon #40
Posted 23 January 2014 - 06:14 PM
Thank you :)/> I know it's not perfect but I try :-p I will be doing more work on the system manager sometime tomorrow since I ended up having a few ideas for improvements! Stay tuned! :)/>
itzstarstruck #41
Posted 02 July 2014 - 01:16 PM
It will put my login continuesly in PENDING!! HELP MEH
JohnSmith41Junk #42
Posted 03 August 2014 - 02:43 PM
It will put my login continuesly in PENDING!! HELP MEH
Quality Post ^^

Anyway, you need to edit the system and manually move your pending account into the users, and rename it to whatever username you chose. Also edit the file, remove the first line, and make the second line the first one. Save and exit, then reboot and enter your password. A bit hacky, but it works if you, like me, can't figure out how to use the admin override! :wacko:/>
Easton_Haaff #43
Posted 17 October 2015 - 07:16 PM
The screenshots aren't working? I click on the link and says its unavailable