ldap域账号登录

$host = "iflytek.com";

$user =  'yimiao@'.$host;//'用户名@域名';

$pswd = "******";

//1.用户登陆认证

$conn = ldap_connect($host) or die( 'Could not connect!' );





if($conn){

    //设置参数

    ldap_set_option ( $conn, LDAP_OPT_PROTOCOL_VERSION, 3 );

    ldap_set_option ( $conn, LDAP_OPT_REFERRALS, 0 ); // Binding to ldap server

    echo $user.'/'.$pswd;

    $bd = ldap_bind($conn, $user, $pswd)  or die ('Could not bind');

    if($bd){

        echo 'ldap_bind success';

    }else{

        echo 'ldap_bind fail';

    }

}else{

    echo 'Unable to connect to AD server';

}
public partial class _Default : System.Web.UI.Page

    {

        protected void Page_Load(object sender, EventArgs e)

        {

            string domain = "iflytek.com";

            string user = Request.Params["user"] + "@" + domain;

            string pwd = Request.Params["pwd"];

            bool adValidate = false;





            try

            {

                DirectoryEntry entry = new DirectoryEntry("LDAP://" + domain, user, pwd);

                object nativeObject = entry.NativeObject;

                adValidate = true;



                Response.Write("true");

            }

            catch (Exception ex)

            {

                Response.Write(ex.Message);

            }

        }

    }

 

你可能感兴趣的:(LDAP)