37 posts
Posted 23 September 2012 - 07:36 PM
Hello people,
I copied this
http://computercraft...oaming_ProfilesI edited it so: Password Server is Computer No. 3
I have 2 Clients, Computer 4 and 5.
Every time i want to log in on a client it says "Not authorised" (or so) ..
Here the codes:
Password ServerSpoiler
term.clear()
term.setCursorPos(1,1)
print("This is a password server. There is no user interaction here.")
print("Please find a computer and login there.")
local firstCycle = true
local validSender = false
local modemSide = "left"
local valid = false
users = { test, test1 }
passwords = { test, test1 }
senders = { 4, 5 }
function bootUp()
rednet.open(modemSide)
end
while true do
validSender = false
if firstCycle then
bootUp()
firstCycle = false
end
senderId, message, distance = rednet.receive()
for i,v in ipairs(senders) do
if v == senderId then
validSender = true
break
end
end
if validSender then
for i,v in ipairs(users) do
if message == v then
valid = true
password = passwords
else
valid = false
end
end
if valid then
rednet.send(senderId, password)
else
rednet.send(senderId, "Not Valid")
end
end
end
Client 1 & 2Spoiler
local locker = true
local failed = true
local attempted_login = true
local password_server = 3
rednet.open("left")
while locker do
attempted_login = false
term.clear()
term.setCursorPos(1,1)
print("Welcome to a USERS PC : Roaming Profile Enabled")
print("What would you like to do?")
print("[1] Login (*)")
print("[2] Shutdown")
write("> ")
local input = read()
if input == "2" then
os.shutdown()
elseif input == "1" then
attempted_login = true
print("Please login…")
write("Username: ")
local username = read()
write("Password: ")
local password = read("*")
rednet.send(password_server, username)
senderId, message, distance = rednet.receive(5)
if password == message then
failed = false
locker = false
term.clear()
term.setCursorPos(1,1)
print("Welcome ", username)
else
print("Not authorised.")
sleep(1)
end
else
print("Command not recognised…")
sleep(2)
end
endHope you can help
1604 posts
Posted 23 September 2012 - 07:40 PM
And… what exactly you need help with?
37 posts
Posted 23 September 2012 - 07:42 PM
And… what exactly you need help with?
Edited sry i fogot o:
1604 posts
Posted 23 September 2012 - 07:45 PM
The usernames and passwords must be strings, so put quotes arround them, that should fix it.
37 posts
Posted 23 September 2012 - 07:48 PM
The usernames and passwords must be strings, so put quotes arround them, that should fix it.
sry i'm stupid in english are quotes this " " ??
1604 posts
Posted 23 September 2012 - 07:49 PM
The usernames and passwords must be strings, so put quotes arround them, that should fix it.
sry i'm stupid in english are quotes this " " ??
Yes, put them arround the usernames and passwords, like this:
users = { "test", "test1" }
passwords = { "test", "test1" }
37 posts
Posted 23 September 2012 - 07:57 PM
The usernames and passwords must be strings, so put quotes arround them, that should fix it.
sry i'm stupid in english are quotes this " " ??
Yes, put them arround the usernames and passwords, like this:
users = { "test", "test1" }
passwords = { "test", "test1" }
still don't work :P/>/>
and it's on a server btw :3
1604 posts
Posted 23 September 2012 - 08:07 PM
Ok, found the error:
for i,v in ipairs(users) do
if message == v then
valid = true
password = passwords[i]
break -- add break here
else
valid = false
end
end
Someone should change the code in the wiki.
37 posts
Posted 23 September 2012 - 08:21 PM
Ok, found the error:
for i,v in ipairs(users) do
if message == v then
valid = true
password = passwords[i]
break -- add break here
else
valid = false
end
end
Someone should change the code in the wiki.
hmm still don't work ://
1604 posts
Posted 23 September 2012 - 08:38 PM
Ok, made new versions of the programs:
Server:
Spoiler
local users = { "user1" = "password1", "user2" = "password2" }
local senders = { 4, 5 }
local function clear()
term.clear()
term.setCursorPos(1, 1)
end
local function connect()
for _,s in ipairs(rs.getSides()) do
if peripheral.isPresent(s) and peripheral.getType(s) == "modem" then
rednet.open(s)
return true
end
end
return false
end
local function isValid(sender)
for _,id in ipairs(senders) do
if id == sender then
return true
end
end
return false
end
if not connect() then
print("No modem found")
return
end
clear()
print("This is a password server. There is no user interaction here.")
print("Please find a computer and login there.")
while true do
local id, msg = rednet.receive()
if isValid(id) then
local usr = textutils.unserialize(msg)
if usr then
if users[usr.username] == usr.password then
rednet.send(id, "PASS_OK")
else
rednet.send(id, "PASS_WRONG")
end
end
end
end
Client:
Spoiler
local password_server = 3
local function clear()
term.clear()
term.setCursorPos(1, 1)
end
local function connect()
for _,s in ipairs(rs.getSides()) do
if peripheral.isPresent(s) and peripheral.getType(s) == "modem" then
rednet.open(s)
return true
end
end
return false
end
local function validateUsr(usr, timeout)
rednet.send(password_server, textutils.serialize(usr))
local t0 = os.clock()
while os.clock() - t0 < timeout do
local id, msg = rednet.receive(timeout - (os.clock() - t0))
if id and msg then
if id == password_server then
if msg == "PASS_OK" then
return true
else
print("Not authorised")
sleep(1)
return false
end
end
else
print("Server not responding")
print("Try again")
sleep(1)
return false
end
end
return false
end
if not connect() then
print("No modem found")
print("Shutting down")
os.shutdown()
end
while true do
clear()
print("Welcome to a USERS PC : Roaming Profile Enabled")
local usr = {}
write("Username: ")
usr.username = read()
write("Password: ")
usr.password = read("*")
if validateUsr(usr, 5) then
clear()
print("Welcome ", usr.username)
break
end
end
I didn't test them, so let me know if they work.
Edit: made some changes to the client
37 posts
Posted 23 September 2012 - 08:53 PM
Ok, made new versions of the programs:
Server:
Spoiler
local users = { "user1" = "password1", "user2" = "password2" }
local senders = { 4, 5 }
local function clear()
term.clear()
term.setCursorPos(1, 1)
end
local function connect()
for _,s in ipairs(rs.getSides()) do
if peripheral.isPresent(s) and peripheral.getType(s) == "modem" then
rednet.open(s)
return true
end
end
return false
end
local function isValid(sender)
for _,id in ipairs(senders) do
if id == sender then
return true
end
end
return false
end
if not connect() then
print("No modem found")
return
end
clear()
print("This is a password server. There is no user interaction here.")
print("Please find a computer and login there.")
while true do
local id, msg = rednet.receive()
if isValid(id) then
local usr = textutils.unserialize(msg)
if usr then
if users[usr.username] == usr.password then
rednet.send(id, "PASS_OK")
else
rednet.send(id, "PASS_WRONG")
end
end
end
end
Client:
Spoiler
local password_server = 3
local function clear()
term.clear()
term.setCursorPos(1, 1)
end
local function connect()
for _,s in ipairs(rs.getSides()) do
if peripheral.isPresent(s) and peripheral.getType(s) == "modem" then
rednet.open(s)
return true
end
end
return false
end
local function validateUsr(usr, timeout)
rednet.send(password_server, textutils.serialize(usr))
local t0 = os.clock()
while os.clock() - t0 < timeout do
local id, msg = rednet.receive(timeout - (os.clock() - t0))
if id and msg then
if id == password_server then
if msg == "PASS_OK" then
return true
else
print("Not authorised")
sleep(1)
return false
end
end
else
print("Server not responding")
print("Try again")
sleep(1)
return false
end
end
return false
end
if not connect() then
print("No modem found")
print("Shutting down")
os.shutdown()
end
while true do
clear()
print("Welcome to a USERS PC : Roaming Profile Enabled")
local usr = {}
write("Username: ")
usr.username = read()
write("Password: ")
usr.password = read("*")
if validateUsr(usr, 5) then
clear()
print("Welcome ", usr.username)
break
end
end
I didn't test them, so let me know if they work.
Edit: made some changes to the client
in the server one i get "bios:206: [string "startup"]:1: '}' expected
1604 posts
Posted 23 September 2012 - 08:59 PM
Change the first line to:
local users = { ["user1"] = "password1", ["user2"] = "password2" }
or
local users = { user1 = "password1", user2 = "password2" }
37 posts
Posted 23 September 2012 - 09:02 PM
Change the first line to:
local users = { ["user1"] = "password1", ["user2"] = "password2" }
or
local users = { user1 = "password1", user2 = "password2" }
Next error: bios:206: [string "startup"]:6: '<eof>' expected
1604 posts
Posted 23 September 2012 - 09:09 PM
Did you copy the exact same code?
37 posts
Posted 23 September 2012 - 09:19 PM
Did you copy the exact same code?
First not. But now it works :P/>/>
i love you so much! <3 ;)/>/>
37 posts
Posted 23 September 2012 - 09:37 PM
Did you copy the exact same code?
Now i have a little offtopic question:
I want the computer to do something if it get's a blue cable input from a bundeled cable how do i "code" this? ^^
1604 posts
Posted 23 September 2012 - 09:39 PM
You need to use the redstone api. It will be something like this:
if rs.testBundledInput("side", colors.blue) then
-- do something here
end