#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2003
    Posts
    17
    Rep Power
    0

    PHP LDAP Userlogin


    Hi All,

    I am Using OpenLDAP .. they already got user and password(ldif files) in the System.

    the only think when user logged in i need to check that username and password in LDAP Server. i need the code how to do it..

    I am using PHP

    $ldap=ldap_connect("localhost") or die("no connection for LDAP");
    $password=crypt($password);


    if($ldap){
    $bind_results=ldap_bind($ldap,"uid=" . $username . ", ou=staff,o=name.com", $password) or die("no user");

    $dn = "ou=staff,o=name.com";
    $filter = "(|(uid=" . $username . "*))";

    $nds_stuff=array("cn","Manager");
    $results=ldap_search($ldap, $dn, $filter, $nds_stuff);
    $info=ldap_get_entries($ldap,$results);

    if($info["count"] != 0){
    header("Location: /index.php");
    }
    else{
    header("Location:../login.php");
    }
    ldap_close($ldap);
    }
    else{
    die("no connection for LDAP");
    }
  2. #2
  3. Psycho Canadian
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Jan 2001
    Location
    Canada
    Posts
    4,846
    Rep Power
    635
    What I do to verify that someone has an account is first search for there uid (or cn or whatever) then log in as them with there userdn(which you get after searching for them) and password, each user should be able to log in to there own account and read everything in it, but shouldn't be able to write to it.

IMN logo majestic logo threadwatch logo seochat tools logo