Guest User

Untitled

a guest
Sep 16th, 2014
444
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. <?php
  2.  
  3. /* CHANGE THESE */
  4. $ldapBaseDomain = 'o=mybase';
  5. $ldapServer = 'ldaps://myipaddress';
  6. $ldapport = 636;
  7. $ldapUsername = 'cn=search,ou=mystaff,ou=myoffice,o=mybase';
  8. $ldapPassword = 'somapassword';
  9.  
  10.  
  11.  
  12.  
  13. /* CHANGE THESE */
  14.  
  15. if (!empty($_POST['username']) && !empty($_POST['password'])) {
  16.  
  17. // filter out ldap wildcards
  18. if (!$_POST['username']) {
  19. die('Please enter a valid username');
  20. }
  21.  
  22. if (!$ldapConnection = @ldap_connect($ldapServer, $ldapport)) {
  23. die('Could not connect to ldap server');
  24. }
  25.  
  26. if (!@ldap_bind($ldapConnection, $ldapUsername, $ldapPassword)) {
  27. die('Could not bind to ldap server');
  28. }
  29. $attributes = array('dn');
  30. $username = $_POST['username'];
  31. // if (!$ldapSearch = @ldap_search($ldapConnection, $ldapBaseDomain, 'cn=' . $_POST['username'])) {
  32.  
  33. if (!$ldapSearch = @ldap_search($ldapConnection, $ldapBaseDomain, '(&(objectClass=user)(cn= '. $_POST['username'] .' ))' , $attributes)) {
  34. die('Could not complete ldap search');
  35.  
  36. }
  37.  
  38. $ldapCount = @ldap_count_entries($ldapConnection, $ldapSearch);
  39.  
  40. if (!$ldapCount) {
  41. die('account not found');
  42. } else {
  43. if (!$ldapEntry = @ldap_get_entries($ldapConnection, $ldapSearch)) {
  44. die('Could not get ldap entry');
  45. }
  46.  
  47. $distinguishedName = $ldapEntry[0]['dn'][0];
  48. print_r($ldapEntry);
  49.  
  50. if (empty($distinguishedName)) {
  51. die('Account information not found');
  52. }
  53.  
  54. if(!@ldap_bind($ldapConnection, $distinguishedName, $_POST['password'])) {
  55.  
  56. print_r($_POST['password']);
  57. print_r($distinguishedName);
  58. die('Password Incorrect');
  59.  
  60. }
  61.  
  62. echo ' <h1>Logged in successfully</h1>
  63. <h2>User Details</h2>';
  64.  
  65. echo '<pre>' . print_r($ldapEntry[0], true) . '</pre>';
  66. }
  67.  
  68. } else {
  69. echo ' <form method="post">
  70. Username: <input name="username"><br>
  71. Password: <input name="password" type="password"><br>
  72. <input type="submit" value="login">
  73. </form>';
  74. }
  75.  
  76. ?>
Advertisement
Add Comment
Please, Sign In to add comment