The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

SOLVED Ldap authentication with windows login

Discussion in 'cPanel Developers' started by Rudra, Dec 8, 2016.

Tags:
  1. Rudra

    Rudra Member

    Joined:
    Nov 2, 2016
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Bangalore
    cPanel Access Level:
    Root Administrator
    Hi all,

    I have been trying to authenticate windows login credentials by using ldap.Below is the code by which i am trying to authenticate the login credentials by accessing active directory of windows server but i am unable to authenticate it.Can anyone please help me resolve the problem.

    Thank you.

    Code:
    <?php
    if(isset($_POST['username']) && isset($_POST['password'])){
    
        $adServer = "192.168.2.14";
      
        $ldap = ldap_connect($adServer);
        $username = $_POST['username'];
        $password = $_POST['password'];
    
        $ldaprdn = 'relyon' . "\\" . $username;
    
        ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3);
        ldap_set_option($ldap, LDAP_OPT_REFERRALS, 0);
    
        $bind =ldap_bind($ldap, $ldaprdn,$password);
    
        if ($bind) {
            $filter="(sAMAccountName=$username)";
            $result = ldap_search($ldap,"dc=relyon,dc=.com",$filter);
            ldap_sort($ldap,$result,"sn");
            $info = ldap_get_entries($ldap, $result);
            for ($i=0; $i<$info["count"]; $i++)
            {
                if($info['count'] > 1)
                    break;
                echo "<p>You are accessing <strong> ". $info[$i]["sn"][0] .", " . $info[$i]["givenname"][0] ."</strong><br /> (" . $info[$i]["samaccountname"][0] .")</p>\n";
                echo '<pre>';
                var_dump($info);
                echo '</pre>';
                $userDn = $info[$i]["distinguishedname"][0];
            }
            @ldap_close($ldap);
        } else {
            $msg = "Invalid email address / password";
            echo $msg ." & ".$ldaprdn;
        }
      
    }else{
    ?>
        <form action="#" method="POST">
            <label for="username">Username: </label><input id="username" type="text" name="username" />
            <label for="password">Password: </label><input id="password" type="password" name="password" />        <input type="submit" name="submit" value="Submit" />
        </form>
    <?php } ?>
    
     
    #1 Rudra, Dec 8, 2016
    Last edited by a moderator: Dec 9, 2016
  2. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    37,163
    Likes Received:
    1,294
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Hello,

    Could you provide some more information on how this relates to the cPanel software or the cPanel server?

    Thank you.
     
Loading...

Share This Page