*/ class LSauth { /** * Check user login * * @param[in] $username The username * @param[in] $password The password * * @retval LSldapObject|false The LSldapObject of the user authificated or false */ public static function authenticate($username,$password) { if (LSsession :: loadLSobject(LSsession :: $ldapServer['authObjectType'])) { $authobject = new LSsession :: $ldapServer['authObjectType'](); $result = $authobject -> searchObject( $username, LSsession :: getTopDn(), LSsession :: $ldapServer['authObjectFilter'] ); $nbresult=count($result); if ($nbresult==0) { // identifiant incorrect LSdebug('identifiant incorrect'); LSerror :: addErrorCode('LSauth_01'); } else if ($nbresult>1) { // duplication d'authentité LSerror :: addErrorCode('LSauth_02'); } elseif ( self :: checkUserPwd($result[0],$password) ) { // Authentication succeeded return $result[0]; } else { LSerror :: addErrorCode('LSauth_01'); LSdebug('mdp incorrect'); } } else { LSerror :: addErrorCode('LSauth_03'); } return; } /** * Test un couple LSobject/pwd * * Test un bind sur le serveur avec le dn de l'objet et le mot de passe fourni. * * @param[in] LSobject L'object "user" pour l'authentification * @param[in] string Le mot de passe à tester * * @retval boolean True si l'authentification à réussi, false sinon. */ public static function checkUserPwd($object,$pwd) { return LSldap :: checkBind($object -> getValue('dn'),$pwd); } } /* * Error Codes */ LSerror :: defineError('LSauth_01', _("LSauth : Login or password incorrect.") ); LSerror :: defineError('LSauth_02', _("LSauth : Impossible to identify you : Duplication of identities.") ); LSerror :: defineError('LSauth_03', _("LSsession : Could not load type of identifiable objects.") ); ?>