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

Password help

Started by 072608, 24 May 2012 - 01:50 AM
072608 #1
Posted 24 May 2012 - 03:50 AM
I'd like to make login thing like Windows for ComputerCraft computer
but i no how to do any coding for this
ComputerCraftFan11 #2
Posted 24 May 2012 - 09:35 AM
To get user input, use read(). read() returns a string so you can do this:

input = read() --Store your input for later
if input == "Hi" then --If you type "Hi" then do this...
  print("Hello!")
else -- If you typed something else
  os.reboot()
end
Lolgast #3
Posted 24 May 2012 - 09:56 AM
To get user input, use read(). read() returns a string so you can do this:

input = read() --Store your input for later
if input == "Hi" then --If you type "Hi" then do this...
  print("Hello!")
else -- If you typed something else
  os.reboot()
end
Note that you have to give the file the name startup if you want to make it start when you start your computer. Otherwise you'll be able to just reboot the computer, and then access everything. If you really want a username and password, and multiple accounts, it's a bit harder. You'll have to use tables. For example, you could use

usertable = {072608="ComputerOwner", ComputerCraftFan11="Pro Coder", Lolgast ="Clueless"} -- A table with usernames and passwords. EDIT: Your username may not begin with a digit. It will throw an error.
print("Username:") -- Make it ask for a username
username = read() -- Input your username
print("Password:") -- Ask for your password
password = read() -- Input password
if usertable[username] == password then -- Checks if the correct password is filled in
print("Logged in as " .. username)
else
print("Wrong username or password")
sleep(2)
os.reboot() -- restarts computer, if you call this file startup it will start the program again.
end
I don't have a computer with minecraft/computercraft right now, so I can't test it, but I guess it would work. I'm not sure what happens if you'd enter Advert as username, for example, because Advert isn't in the usertable as a key, it might throw an error, ending the program. Maybe someone else knows this.

EDIT: Testing it right now.
EDIT2: Done with testing. It works, but note that your usernames may not begin with a digit. So you can't make a username 072608, but u072608 will work. Also a wrong username will correctly result in rebooting the system.
072608 #4
Posted 25 May 2012 - 03:31 AM
Well I wanted something that be like windows like it won't set a password or account to you make one
PixelToast #5
Posted 25 May 2012 - 03:34 AM
use
status,text=pcall(read)
status will return false if it was ctrl t'd
Luanub #6
Posted 25 May 2012 - 03:35 AM
Take a look at my login script and API located here http://www.computercraft.info/forums2/index.php?/topic/1397-login-scriptapi-with-multi-users-and-permissionupdated-v11/

You can use the API to make your own login script using the API's function which include multiple user support, permissions(admin, user), and the ability to create new accounts.
PixelToast #7
Posted 25 May 2012 - 03:37 AM
Take a look at my login script and API located here http://www.computerc...ionupdated-v11/

You can use the API to make your own login script using the API's function which include multiple user support, permissions(admin, user), and the ability to create new accounts.
ill give it a try :)/>/>