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

Login Server

Started by tysciman7, 09 June 2013 - 07:50 AM
tysciman7 #1
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:


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
GravityScore #2
Posted 09 June 2013 - 10:30 AM
I don't understand your question. You are trying to make a server based door locking system, and are asking how you can have the server validate the username and password, because currently the server only validates the password?

If so, you haven't shown us the client code, as modifications are needed client side so it is able to send the username as well as the password to the server.
Imque #3
Posted 11 June 2013 - 09:24 AM
On the wiki there is a really good example of client and server login code. If you modify the client on we're the login is successful to output a red stone signal you should be alright.