Harrington Web

PHP LDAP

Thursday, November 1, 2007

Simple function to check if a username and password is correct with Active Directory.

function checkNTuser($username, $pasword){
  $Domain="SOMEDOMAIN";
  $Server="ldap://someaddress.co";
  $auth=$username."@".$Domain;
  if (extension_loaded('ldap')){
    echo "LDAP Module Enabled";
    $connect=ldap_connect($Server);
    if ($bind=ldap_bind($connect, $auth, $password)){
      ldap_close($connect);
      echo "Success";
      return(true);
    }
    else {
      ldap_close($connect);
      echo "Failed";
      return(false);
    }
  }
}