美文网首页PYTHON
php和python的AD域认证

php和python的AD域认证

作者: 葵花点穴 | 来源:发表于2019-03-28 09:07 被阅读0次

    <?php

    $filter = "(mail=name@test.com)";

    //$ldapuser  = 'cmdbldap';    // 域用户名

    //$ldappass = "CmdbLd@p";  // 域用户密码

    $mail  = 'name@test.com';    // 域用户名

    $pwd = "password";

    $basedn = "OU=jianshu,DC=jianshu,DC=com";

    // 这里配置域服务器的ip或者域名

    $ldapconn = ldap_connect("ldap.jianshu.com.cn") or die("Could not connect to LDAP server.");

    ldap_set_option ( $ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3 );

    ldap_set_option ( $ldapconn, LDAP_OPT_REFERRALS, 0 );

    if($ldapconn){

    $ldapbind = ldap_bind($ldapconn, $ldapuser, $ldappass) or die ("Error trying to bind: ".ldap_error($ldapconn));

    if ($ldapbind) {

    echo "LDAP bind successful...\n\n";

    $result = ldap_search($ldapconn,$basedn, $filter) or die ("Error in search query: ".ldap_error($ldapconn));

    var_dump($result);

    $data = ldap_get_entries($ldapconn, $result);

    var_dump($data[0]['dn']);

    if ( $data[0] ){

    $sr = ldap_bind( $ldapconn, $data[0]['dn'],'');

    print_r("$sr\n");

    if ( $sr ){

    echo "True!\n";

    }else{

    echo "sencond false!\n";

    }

    }else{

    echo "first false!\n";

    }

    echo "\n";

    }

    }else{

    echo "False";

    }

    ldap_close($ldapconn);

    ?>

    相关文章

      网友评论

        本文标题:php和python的AD域认证

        本文链接:https://www.haomeiwen.com/subject/lcmdsxtx.html