Posted 11 September 2012 - 03:58 AM
Hi all, i'm new here and to lua, my god it makes my brain hurt, i came across this code http://computercraft.info/wiki/index.php?title=Login_with_Roaming_Profiles the other day, i wish to edit it to contain "access" levels for various users, spent a night fiddling around with it but i know only the basics about lua, tables are difficult to get my head around. anyway, probably butchered this guys lovely code but here is my modification
Client :
os.pullEvent = os.pullEventRaw
local accesslevel = 4 – security level
local locker = true
local failed = true
local attempted_login = true
local password_server = 0 – change to the ID of your password server computer
rednet.open("top") – change to the side your rednet modem is on
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
senderId, msg, distance = rednet.receive(5)
local access = textutils.unserialize(msg)
if accesslevel <= access then
failed = false
locker = false
term.clear()
term.setCursorPos(1,1)
print("Welcome ", username)
else
print("Not authorised.")
sleep(1)
end
end
else
print("Command not recognised…")
sleep(2)
end
end
Server :
os.pullEvent = os.pullEventRaw
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 = "top" – change to the side of the computer your modem is on
local valid = false
users = { "username1", "username2", "username3" } –make sure users and passwords line up
passwords = { "password1", "password2", "password3" }
accesslevels = { 1, 5, 3 }
senders = { 1, 2, 15, 17 } – computer ID's of the computers you want to accept requests from
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
accesslevel = textutils.serialize(accesslevels)
else
valid = false
end
end
if valid then
–rednet.send(senderId, password)
rednet.broadcast(password)
sleep(2)
–rednet.send(senderId, accesslevel)
rednet.broadcast(accesslevel)
else
rednet.send(senderId, "Not Valid")
end
end
end
can anyone help me please? sorry if isound noobeh :D/>/>
Client :
os.pullEvent = os.pullEventRaw
local accesslevel = 4 – security level
local locker = true
local failed = true
local attempted_login = true
local password_server = 0 – change to the ID of your password server computer
rednet.open("top") – change to the side your rednet modem is on
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
senderId, msg, distance = rednet.receive(5)
local access = textutils.unserialize(msg)
if accesslevel <= access then
failed = false
locker = false
term.clear()
term.setCursorPos(1,1)
print("Welcome ", username)
else
print("Not authorised.")
sleep(1)
end
end
else
print("Command not recognised…")
sleep(2)
end
end
Server :
os.pullEvent = os.pullEventRaw
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 = "top" – change to the side of the computer your modem is on
local valid = false
users = { "username1", "username2", "username3" } –make sure users and passwords line up
passwords = { "password1", "password2", "password3" }
accesslevels = { 1, 5, 3 }
senders = { 1, 2, 15, 17 } – computer ID's of the computers you want to accept requests from
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
accesslevel = textutils.serialize(accesslevels)
else
valid = false
end
end
if valid then
–rednet.send(senderId, password)
rednet.broadcast(password)
sleep(2)
–rednet.send(senderId, accesslevel)
rednet.broadcast(accesslevel)
else
rednet.send(senderId, "Not Valid")
end
end
end
can anyone help me please? sorry if isound noobeh :D/>/>