且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用 iOS 应用对 Active Directory 进行身份验证

更新时间:2022-03-28 21:40:01

好的,这是我用来连接到 ldap 服务器的 PHP.我不是 100% 确定这里发生了什么,我从我公司的 IT 协调员那里得到了这个代码.我了解所有绑定和搜索部分,但我没有得到整个事情的 ldap_set_option 部分.反正这样设置好之后,就可以调用php脚本的URL并传入参数了.看一看 PHP,以及下面的 url 示例.

Ok, so this was the PHP i used to make the connection to the ldap server. i am not 100% sure what is happening here, i got this code from IT Coordinator at my company. I understand all the binding and searching parts, but i dont get the the ldap_set_option part of this whole thing. Anyway after setting it up this way, you can then call the URL of the php script and pass it parameters. take a look at the PHP, and the url example with be below.

<?php
//Connection parameters
$dn = "DC=network,DC=net";
$host = "ldap://ldap.network.com";
$port = 1111

$user = $_GET['user'];
$pass = $_GET['pass'];

//$user = "user@network.net";
//$pass = "pass";

$filter = "memberof";
$keyword = "CN=USSC_ALL,CN=Users,DC=network,DC=net";

$filter = "objectclass";
$keyword = "user";

$filter = "objectcategory";
$keyword = "CN=Person,CN=Schema,CN=Configuration,DC=network,DC=net";

//The real thing with PHP
if (!empty($keyword) and !empty($dn)) {
//Connect to the AD
$adConn = ldap_connect($host, $port) or die("Could not connect!");

//Set protocol verison
ldap_set_option($adConn, LDAP_OPT_PROTOCOL_VERSION, 3) or die ("Could not set ldap     protocol1");

//Set referrals... Won't work without this...
ldap_set_option($adConn, LDAP_OPT_REFERRALS, 0) or die ("Could not set ldap protocol2");

//Bind the user
$bd = ldap_bind($adConn, $user, $pass) or die ("Could not bind");

echo $bd;

 //End binding
ldap_unbind($adConn);



} else {
   echo "<p>No results found!</p>";
}

?>


</body>
</html>  

好的,现在您要做的就是将用户名和密码传递给脚本,它会返回绑定.那会给你真假.意思是如果绑定成功就是用户名和密码的正确组合.

Ok so now all you have to do is pass a username and password to the script and it will return the bind. that will give you either true or false. meaning if it bound successfully it is a correct combination of username and password.

我是这样称呼它的:

http://192.268.192.1/ldap.php?user=(username here)&pass=(password here)

这是我采取的方法,我认为这是一个非常简单的答案.

This is the approach that i took, and i think it is a very simple answer.