Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $server="XXX.XXX.XXX.XXX";
- $dn = "cn=$username, ";
- $basedn="ou=users, ou=accounts, dc=domain, dc=com";
- if (!($connect = ldap_connect($server))) {
- die ("Could not connect to LDAP server");
- }
- if (!($bind = ldap_bind($connect, "$dn" . "$basedn", $password))) {
- die ("Could not bind to $dn");
- }
- $sr = ldap_search($connect, $basedn,"$filter");
- $info = ldap_get_entries($connect, $sr);
- $fullname=$info[0]["displayname"][0];
- $fqdn=$info[0]["dn"];
- <?php
- //We just need six varaiables here
- $baseDN = 'CN=Users,DC=domain,DC=local';
- $adminDN = "YourAdminDN";//this is the admin distinguishedName
- $adminPswd = "YourAdminPass";
- $username = 'Username';//this is the user samaccountname
- $userpass = 'UserPass';
- $ldap_conn = ldap_connect('ldaps://yourADdomain.local');//I'm using LDAPS here
- if (! $ldap_conn) {
- echo ("<p style='color: red;'>Couldn't connect to LDAP service</p>");
- }
- else {
- echo ("<p style='color: green;'>Connection to LDAP service successful!</p>");
- }
- //The first step is to bind the administrator so that we can search user info
- $ldapBindAdmin = ldap_bind($ldap_conn, $adminDN, $adminPswd);
- if ($ldapBindAdmin){
- echo ("<p style='color: green;'>Admin binding and authentication successful!!!</p>");
- $filter = '(sAMAccountName='.$username.')';
- $attributes = array("name", "telephonenumber", "mail", "samaccountname");
- $result = ldap_search($ldap_conn, $baseDN, $filter, $attributes);
- $entries = ldap_get_entries($ldap_conn, $result);
- $userDN = $entries[0]["name"][0];
- echo ('<p style="color:green;">I have the user DN: '.$userDN.'</p>');
- //Okay, we're in! But now we need bind the user now that we have the user's DN
- $ldapBindUser = ldap_bind($ldap_conn, $userDN, $userpass);
- if($ldapBindUser){
- echo ("<p style='color: green;'>User binding and authentication successful!!!</p>");
- ldap_unbind($ldap_conn); // Clean up after ourselves.
- } else {
- echo ("<p style='color: red;'>There was a problem binding the user to LDAP :(</p>");
- }
- } else {
- echo ("<p style='color: red;'>There was a problem binding the admin to LDAP :(</p>");
- }
- ?>
- ldap_bind($connect, "", "")
- $sr = ldap_search($connect, $base_dn, "(sAMAccountName=$username)")
- ldap_bind($connect, "DN=LDAP_App,OU=Users,DC=Domain,DC=com", "thePassword")
- $sr = ldap_search($connect, $base_dn, "(sAMAccountName=$username)")
Add Comment
Please, Sign In to add comment