Refactor ldapauthenticate