Last active
February 10, 2021 14:39
-
-
Save thejeffreystone/2312274 to your computer and use it in GitHub Desktop.
PHP LDAP Function to verify user credentials
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function verifyLdapUser($username,$password) | |
{ | |
$DomainName=LDAPDOMAIN; // name = domain | |
$ldap_server=LDAP; // server = ldap://doman.co | |
// returns true when user/pass binds to LDAP/AD. | |
$auth_user=$username."@".$DomainName; | |
//Check to see if LDAP module is loaded. | |
if (extension_loaded('ldap')) { | |
if($connect=@ldap_connect($ldap_server)){ | |
//echo "connection ($ldap_server): "; | |
if($bind=@ldap_bind($connect, $auth_user, $password)){ | |
//echo "true <BR>"; | |
@ldap_close($connect); | |
return true; | |
} else { | |
//send error message - password incorrect | |
@ldap_close($connect); | |
return false; | |
} | |
} | |
} else { | |
//send message - could not connect to domain | |
@ldap_close($connect); | |
return false; | |
} | |
// send message - ldap module not loaded | |
@ldap_close($connect); | |
return(false); | |
}//end function verifyLdapUser |
Top, thanks a lot for that! Works like a charm.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Merci beaucoup!