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

    Join Date
    Apr 2012
    Posts
    4
    Rep Power
    0

    Simple LDAP Authentication using PHP


    Hi everyone,

    I am a newbie to LDAP...I completely do not know how it works,how is it configured,and even how it is run . I just need this particular functionality to be implemented within the next few days..I have implemented a user login authentication in PHP using MySQL---in a file login.php. I need to implement the same authentication process using LDAP in the same file.So i am basically doing
    1.SQL Authentication
    2.LDAP Authentication

    I have downloaded this particular software OpenLDAP for Windows- from userbooster.de

    But I do not know how to even use it...tried to find a lot of info,but nothin was clear.i just understood a few examples from php.net

    So here is what I need to do exactly,
    1.I have a MySQl Database -sqlia and Table -user with fields "uname" and "pass".I have around 25 entries.
    2. I need to know how to store this MySQL data in an LDAP directory and how to retrieve necessary data from LDAP .
    3. Finally,I need to run a query based on whether an entered username and password matches in the LDAP directory,thereby authenticating the user.
    This whole process should be done in PHP.

    Importantly,this whole process should be done in Windows 7,not in any Linux based environment.

    I understand this process might take around 20 - 30 LOC , but someone please help me out..This s really important,Have been breaking my head for the last 2 weeks and not able to get anywhere.
    Waiting for a response !
    Thanks.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2008
    Posts
    120
    Rep Power
    8
    Typically you would authentic the user by querying LDAP. Is there a particular reason you want to use two forms of authentication? Also, is this Active Directory based LDAP?
    Last edited by gmrstudios; May 4th, 2012 at 02:04 PM.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2012
    Posts
    4
    Rep Power
    0

    LDAP Authentication-PHP


    Originally Posted by gmrstudios
    Typically you would authentic the user by querying LDAP. Is there a particular reason you want to use two forms of authentication? Also, is this Active Directory based LDAP?
    I am doing a project.So its just a proposed concept to have two levels of Authentication..to make the database a bit more secure..And i do not know what Active LDAP directory what you are talking about... I just saw a lot of Active directories- OpenLDAP for Windows,ApacheDS..problem is i do not even know even to configure them..downloaded Open lDAP for windows from userbooster.de
    Can u help me out..need this to be done by tomoro.Metion ur mail id ,i will send u my files.


    This is my login code.I need to fit in the LDAP authentication just anywhere inside after SQL query statement.

    Database name-sqlia
    Table-user
    field-uname,pass

    Help me out.

    <?php
    require("dbconnect.php");
    if(isset($_COOKIE['username']))
    {
    setcookie('username','');
    }


    if((isset($_POST["uname"]))&&(isset($_POST["pass"])))
    {
    $uname=$_POST["uname"];
    $pass=$_POST["pass"];
    $count=0;
    if($uname && $pass)
    {
    $query="select uname from user where uname='$uname' and pass='$pass'";
    $a=mysql_query($query,$con);
    $row=mysql_fetch_row($a);
    $count=mysql_num_rows($a);

    if($count!=0)
    {

    $username=$row[0];
    setcookie("username",$username);
    header("location:http://localhost/New1/login_y.php");
    mysql_close();
    // echo "<input type='hidden' value=";
    // echo "$row[0]";
    // echo " name='a'>";
    //$_COOKIE["uname"]=$uname;
    //echo $temp;
    //echo "Login Success";
    }
    else
    {
    ?>
    <div style="position:absolute;left:15px;top:200px;width:400px;height:20px;z-index:0;"> Incorrect Username and Passsword</div>
    <?php

    }
    }
    else
    {
    ?>
    <div style="position:absolute;left:15px;top:200px;width:200px;height:20px;z-index:0;"> Enter User Name and Password</div>

    <?php
    }

    }

    ?>

    Thanks

IMN logo majestic logo threadwatch logo seochat tools logo