Posted 06 August 2012 - 02:57 PM
I've got a problem with multiple usernames and passwords for logging into a computer, for some reason only one user (MilkBottle) will work and the other users (MilkCarton) gets the incorrect password notification even when they type it correctly.
EDIT: Just to add more detail to the post, I plan on making the system have the ability to add/remove usernames and passwords to the server remotely, hence me trying to use a table instead of plain variables. I don't think I understand yet how tables behave, I need both my key and value to be strings, I want the server to check if a username(key) exists in the table, then send the asscociated password(value) of the key back to the client where the client software then checks to see if the typed password variable matche the password(value) that was sent back from the server. What I don't understand is why one entry works while the others don't…
Here is the code for the Server:
And here is the code for the computer or where the user logs in:
I have tried for hours and searched the internet for help but can't find any and I'm getting really frustrated.
Any help will be appreciated, thanks.
EDIT: Just to add more detail to the post, I plan on making the system have the ability to add/remove usernames and passwords to the server remotely, hence me trying to use a table instead of plain variables. I don't think I understand yet how tables behave, I need both my key and value to be strings, I want the server to check if a username(key) exists in the table, then send the asscociated password(value) of the key back to the client where the client software then checks to see if the typed password variable matche the password(value) that was sent back from the server. What I don't understand is why one entry works while the others don't…
Here is the code for the Server:
term.clear()
term.setCursorPos(1,1)
print("Milk Industries Server 2012.")
print("Server Log:n")
local on = true
local firstCycle = true
local validSender = false
local modemSide = "left"
local valid = false
users = {}
users = {MilkBottle=("bananarama"), Jesus=("lolercat"), MilkCarton=("raptorjesus")}
senders = {}
senders = {12, 12, 12}
function bootUp()
rednet.open(modemSide)
end
while on == true do
validSender = false
if firstCycle then
bootUp()
end
senderId, message, distance = rednet.receive()
for i,v in ipairs(senders) do
if v == senderId then
validSender = true
break
else
end
end
if validSender == true then
for k,v in pairs(users) do
if message == k then
awesome = v
print(message.." "..awesome)
valid = true
else
valid = false
end
end
if valid == true then
rednet.send(senderId, awesome)
else
rednet.send(senderId, "Incorrect!")
end
end
end
And here is the code for the computer or where the user logs in:
local locker = true
local failed = true
local attempted_login = true
local password_server = 11
securityDoor = false
rednet.open("top")
function Clear()
term.clear()
term.setCursorPos(1,1)
end
Clear()
write("Loading... 0%")
sleep(0.1)
function MainScreen()
attempted_login = false
Clear()
textutils.slowPrint("Milk Industries Nuclear Reactor Control.nAUTHORISED PERSONNEL ONLY!")
print("")
print("Please input the command you wish to perform.")
print("")
print("=================================")
print("1. Login to Control Panaln2. Shutdown")
print("=================================")
while true do
event, var=os.pullEvent("char")
if var == ("1") then
Login()
elseif var ==("2") then
Shutdown()
end
end
end
Clear()
write("Loading... 4%")
sleep(0.1)
function Login()
Clear()
print("Please enter your username and password.n n")
LoginInput()
end
function LoginInput()
attempted_loging = true
print("Username: ")
username = read()
print("Password: ")
serpassword = read("*")
rednet.send(password_server, username)
senderId, message, distance = rednet.receive(3)
if serpassword == message then
failed = false
locker = false
Verified()
else
Failed()
end
end
Clear()
write("Loading... 28%")
sleep(0.1)
function Shutdown()
Clear()
textutils.slowPrint("Shutting down console...")
sleep(1)
os.shutdown()
end
Clear()
write("Loading... 39%")
sleep(0.1)
function Failed()
Clear()
print("Incorrect login details, please try again.")
print("")
LoginInput()
end
Clear()
write("Loading... 51%")
sleep(0.1)
function Verified()
Clear()
reactorLaunch = false
write("Welcome! Please choose a command.nn")
print("===================================")
print("1. Security Management")
if reactorLaunch == true then
print("2. Disable Reactor Monitor")
else
print("2. Activate Reactor Monitor")
end
print("3. Reactor Controls")
print("4. Log out")
print("===================================")
while true do
event, var =os.pullEvent("char")
if var == ("1") then
Security()
elseif var ==("2") and reactorLaunch then
DisableMon()
elseif var ==("2") then
EnableMon()
elseif var ==("3") then
ReactorCtrl()
elseif var ==("4") then
Clear()
textutils.slowPrint("Logging out...")
sleep(2)
Clear()
os.reboot()
end
end
end
Clear()
write("Loading... 72%")
sleep(0.1)
function Security()
Clear()
textutils.slowPrint("Security Menu. Please enter your command.")
print("")
print("===================================")
if securityDoor == true then
print("1. Close Reinforced Doors")
elseif securityDoor == false then
print("1. Open Reinforced Doors")
end
print("2. Main Menu")
print("===================================n")
while true do
event, var =os.pullEvent("char")
if var == ("1") and securityDoor == true then
print("Warning! Closing Reinforced Doors!")
rs.setOutput("back", false)
sleep(2)
securityDoor = false
Security()
elseif var == ("1") and securityDoor == false then
print("Warning! Opening Reinforced Doors!")
rs.setOutput("back", true)
sleep(2)
securityDoor = true
Security()
elseif var == ("2") then
Verified()
end
end
end
Clear()
write("Loading... 94%")
sleep(0.1)
Clear()
write("Loading... 100%")
sleep(1)
while locker do
MainScreen()
end
I have tried for hours and searched the internet for help but can't find any and I'm getting really frustrated.
Any help will be appreciated, thanks.