在没有PHP ldap_bind的情况下,如何在AD中验证用户名和密码?

时间:2019-03-28 18:21:11

标签: php

我有一个通过服务帐户连接并绑定到AD的php文件,对此没有任何问题。 我有一个HTML表单,要求输入user namepassword。 我需要一种方法来针对AD验证用户的凭据 当用户在表单中输入其用户名和密码时。

我无法使用ldap_bind函数,因为我们的用户无权执行此操作。

假设PHP有一个auth类,但是我不知道如何使它工作。有人可以帮我吗?如果auth类不起作用,我还可以使用哪些其他代码来验证凭据并将其添加到我的PHP页面? 以下是我的php页面:

<?php

// Connect to AD========================================================

include('studentFormAuth.html');

$ldapusername = 'service_account_name';

$ldappassword = "service_account_password";

$server = 'xx.xx.xx.xx';

$domain = '@abc.com';

$port = 389;

$connection = ldap_connect($server, $port);

if (!$connection) {

    exit('Connection failed');

}

// Settings for AD======================================================

ldap_set_option($connection, LDAP_OPT_PROTOCOL_VERSION, 3);

ldap_set_option($connection, LDAP_OPT_REFERRALS, 0);

$bind = @ldap_bind($connection, $ldapusername.$domain, $ldappassword);

if (!$bind) {

    exit('Binding failed');

}

// Verify user credentials auth function=============================================

$auth = new Auth($connection, $_POST['usern'].$domain, $_POST['password']);

// begin validation 

$auth->start();

if ($auth->getAuth()) {

    // content for validated users

    echo 'user name is: ' $_POST['usern'].$domain;

} else {

    echo 'Cannot verify user';
}

// log users out

$auth->logout();

0 个答案:

没有答案
相关问题