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

Multiple Users/Password lock(computer lock version)

Started by fixerpro, 31 January 2013 - 06:40 PM
fixerpro #1
Posted 31 January 2013 - 07:40 PM
Find Code here: http://pastebin.com/raw.php?i=x12pz3JZ

srry cant post any desc or pics now,will be up soon
only thing i can tell you its a computer lock
Chris54721 #2
Posted 01 February 2013 - 08:53 AM
Why you don't use a table for users? Like this:

local users = {"user1", "user2", "user3", "etc"}

Then use a for loop to scan the table:

for i=1, #users do
   if users[i] == input then
	   print("Success!")
   else
	   print("Bad Login")
   end
end
fixerpro #3
Posted 01 February 2013 - 05:46 PM
I dont really know how to use and make tables,plus i dont want it to hard or advanced for players to use
Mikee251 #4
Posted 01 February 2013 - 06:06 PM
The problem with using tables to store passcodes/users is that they can often be found and cracked easily. Never use them if you are doing it client-side. Maybe server side. Here is some code I did that uses files to log them in, plus if the computers shutdown, none of the data will be lost:

Server code:

logged = 0
function checklogin(username,password)
if username == nil or password == nil then
shell.run("host")
else
local file = fs.open(username, "r")
if password == file.readLine() then
logged = 1
else
logged = -1
end end end


while true do
id,msg = rednet.receive()
print("User " .. id .. " has sent out the message: " .. msg)

if msg == ("login") then
local idlat = id
logged = 0
print("Received Login request")
id,msg = rednet.receive()
if msg ~= "" then
print("Received Username")
local user = msg
id,msg = rednet.receive()
if msg ~= "" then
print("Received Password")
local pass = msg
checklogin(user,pass)
if logged == 1 then
print("confirmed")
rednet.send(idlat,"confirmed")
else if logged == -1 then
print("wrong combination")
rednet.send(idlat, "wrong")
else
end end else rednet.send(idlat,"wrong") end else rednet.send(idlat,"wrong") end
else

end

end

Clientcode(I cutout the rest of the client, just command prompt stuff):

Logined = 0
function login(name,pass)
print("Username?")
local user = io.read()
print("Password?")
local pass = io.read()
rednet.send(109, "login")
print("Sent request")
sleep(.1)
rednet.send(109, user)
print("Sent User")
sleep(.1)
rednet.send(109, pass)
print("Sent Password")
id,msg = rednet.receive(5)
print("Received response")
if msg == nil then
print("No response")
else if id == 109 and msg == ("confirmed") then
print("Login Successful")
Logined = 1
os.sleep(1)
return true
else if msg == ("wrong") then
print("Wrong combination")
else print("login failed")
shell.run("command")
end end end end

Start the server, and you can either: A. manually set up accounts or B.do it automatically. I do it manually so that it does not get spammed files. To make an account type in like edit (typeusername) then for the code put the password you want for it, save, exit and run the server. Then go to the computer and start it. The computer will ask for a Username and a password and you enter both and if correct, it logs you in.
Stupidcreeper123 #5
Posted 03 March 2013 - 03:05 AM
The problem with using tables to store passcodes/users is that they can often be found and cracked easily. Never use them if you are doing it client-side. Maybe server side. Here is some code I did that uses files to log them in, plus if the computers shutdown, none of the data will be lost:

Server code:

logged = 0
function checklogin(username,password)
if username == nil or password == nil then
shell.run("host")
else
local file = fs.open(username, "r")
if password == file.readLine() then
logged = 1
else
logged = -1
end end end


while true do
id,msg = rednet.receive()
print("User " .. id .. " has sent out the message: " .. msg)

if msg == ("login") then
local idlat = id
logged = 0
print("Received Login request")
id,msg = rednet.receive()
if msg ~= "" then
print("Received Username")
local user = msg
id,msg = rednet.receive()
if msg ~= "" then
print("Received Password")
local pass = msg
checklogin(user,pass)
if logged == 1 then
print("confirmed")
rednet.send(idlat,"confirmed")
else if logged == -1 then
print("wrong combination")
rednet.send(idlat, "wrong")
else
end end else rednet.send(idlat,"wrong") end else rednet.send(idlat,"wrong") end
else

end

end

Clientcode(I cutout the rest of the client, just command prompt stuff):

Logined = 0
function login(name,pass)
print("Username?")
local user = io.read()
print("Password?")
local pass = io.read()
rednet.send(109, "login")
print("Sent request")
sleep(.1)
rednet.send(109, user)
print("Sent User")
sleep(.1)
rednet.send(109, pass)
print("Sent Password")
id,msg = rednet.receive(5)
print("Received response")
if msg == nil then
print("No response")
else if id == 109 and msg == ("confirmed") then
print("Login Successful")
Logined = 1
os.sleep(1)
return true
else if msg == ("wrong") then
print("Wrong combination")
else print("login failed")
shell.run("command")
end end end end

Start the server, and you can either: A. manually set up accounts or B.do it automatically. I do it manually so that it does not get spammed files. To make an account type in like edit (typeusername) then for the code put the password you want for it, save, exit and run the server. Then go to the computer and start it. The computer will ask for a Username and a password and you enter both and if correct, it logs you in.
Thanks This Is What I've Been Searching For