Posted 09 June 2013 - 09:50 AM
Ok for the dicks that like to be smart with me this isnt my program or code. I need help making it so the server checks a username that the user types into the client computer and like it is already set up to check the password. So i need to change it so that the server verifies that the username and password are right no matter what computer they use but of course you need to send back to the client that the username and passs are correct or not.
The Code:
The Code:
local myid = os.computerID()
local doorList = { id, }
local passwordForDoor = { "","" }
mon=peripheral.wrap("bottom")
print("Access Terminal")
rednet.open("back")
print("Computer id for Access Terminal is "..tostring(myid))
function findIndexForId(id)
for i,v in ipairs(doorList) do
if id == v then
return i
end
end
return 0
end
--[[ for future implementation ]]--
function setPasswordForLock(id,password)
local i = findIndexForId(id)
if i == 0 then
return false
end
passwordForDoor[i] = password
print("in setPasswordForLock"..id..password)
return true
end
function checkPasswordForLock(id,password)
local i = findIndexForId(id)
if i == 0 then
return -1
end
if passwordForDoor[i] == password then
return 1
else
return 0
end
end
--[[ Not needed yet, for later when we allow remove password changes ]]-
function saveData()
local myfile = io.open("/doorpw.dat","w")
print(tostring(myfile))
print("1")
for i,pw in ipairs(passwordForDoor) do
myfile:write(pw)
end
print("4")
myfile:close()
end
local isValid = 0
while true do
local timeString = textutils.formatTime(os.time(),false)
senderId, message, distance = rednet.receive()
isValid = checkPasswordForLock(senderId, message)
if isValid == -1 then
print("server "..senderId.." sent us a request but is not in our list")
elseif isValid == 1 then
rednet.send(senderId, "Valid")
mon.scroll(1)
mon.setCursorPos(1,4)
mon.write("Access from "..senderId.." at "..timeString)
else
rednet.send(senderId, "Not Valid")
mon.scroll(1)
mon.setCursorPos(1,4)
mon.write("Failure from "..senderId.." at "..timeString)
end
end