Advertisement
Guest User

Untitled

a guest
May 27th, 2016
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.49 KB | None | 0 0
  1. <?php
  2.  
  3. if(isset($_POST['username']) && isset($_POST['password'])){
  4.  
  5. $adServer = "ldap://test.com";
  6.  
  7. $ldap = ldap_connect($adServer);
  8. $username = $_POST['username'];
  9. $password = $_POST['password'];
  10.  
  11. $ldaprdn = 'mw' . "\" . $username;
  12.  
  13. ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3);
  14. ldap_set_option($ldap, LDAP_OPT_REFERRALS, 0);
  15.  
  16. $bind = @ldap_bind($ldap, $ldaprdn, $password);
  17.  
  18.  
  19. if ($bind) {
  20. $filter="(sAMAccountName=$username)";
  21. $result = ldap_search($ldap,"dc=mw,dc=aa,dc=cd,dc=ca",$filter);
  22. ldap_sort($ldap,$result,"sn");
  23. $info = ldap_get_entries($ldap, $result);
  24. for ($i=0; $i<$info["count"]; $i++)
  25. {
  26. if($info['count'] > 1)
  27. break;
  28. echo "<p>You are accessing <strong> ". $info[$i]["sn"][0] .", " . $info[$i]["givenname"][0] ."</strong><br /> (" . $info[$i]["samaccountname"][0] .")</p>n";
  29. echo '<pre>';
  30. var_dump($info);
  31. echo '</pre>';
  32. $userDn = $info[$i]["distinguishedname"][0];
  33. }
  34. @ldap_close($ldap);
  35. header( "Location: http://test.com" );
  36. } else {
  37. $msg = "Invalid email address / password";
  38. echo $msg;
  39. }
  40.  
  41. }else{
  42. ?>
  43.  
  44. <html>
  45. <META HTTP-EQUIV="Pragma" CONTENT="no-cache">
  46. <META HTTP-EQUIV="Expires" CONTENT="-1">
  47. <head>
  48.  
  49.  
  50. <!-- Bypass Compatiblity View (Super Important) -->
  51. <meta http-equiv="X-UA-Compatible" content="IE=9">
  52. <meta charset="utf-8">
  53. <meta name="viewport" content="width=device-width, initial-scale=1">
  54.  
  55. <!-- Latest compiled and minified CSS -->
  56. <link rel="stylesheet" href="css/bootstrap.min.css">
  57. <!-- jQuery library -->
  58. <link href="https://fonts.googleapis.com/css?family=Titillium+Web" rel="stylesheet" type="text/css">
  59. <!-- My CSS page -->
  60. <link rel="stylesheet" type="text/css" href="css/bootstrap-select.min.css">
  61.  
  62. <link rel="stylesheet" type="text/css" href="css/style.css">
  63.  
  64. <script src="js/jquery.min.js"></script>
  65. <!-- Latest compiled JavaScript -->
  66. <script src="js/bootstrap.min.js"></script>
  67. <script src="js/bootstrap-select.min.js"></script>
  68. <script src="js/jquery.validate.min.js"></script>
  69. <script src="page.js"></script>
  70. <!-- Google Font -->
  71. </head>
  72.  
  73. <body class="login-body">
  74.  
  75. <div class="container" style="margin-top:30px">
  76. <div class="row">
  77. <div class="col-md-4 col-md-offset-4">
  78.  
  79. </div>
  80. </div>
  81. </div>
  82. <div class="container">
  83. <div class="row">
  84.  
  85. <div class="col-md-4 col-md-offset-4">
  86. <div class="panel panel-default" >
  87.  
  88. <div class="panel-heading">
  89. <h1 class="panel-title"><strong>Sign in</strong></h1>
  90. </div>
  91.  
  92. <div class="panel-body">
  93.  
  94. <form action="#" method="POST" class="form-signin">
  95.  
  96.  
  97. <div class="form-group">
  98. <label for="username" class="control-label">Username</label>
  99. <div class="input-group">
  100. <span class="input-group-addon"><i class="glyphicon glyphicon-user" aria-hidden="true"></i></span>
  101. <input type="text" class="form-control" name="username" id="username" placeholder="Enter your Username"/>
  102. </div>
  103. </div>
  104.  
  105. <div class="form-group">
  106. <label for="password" class="control-label">Password</label>
  107. <div class="input-group">
  108. <span class="input-group-addon"><i class="glyphicon glyphicon-lock" aria-hidden="true"></i></span>
  109. <input type="password" class="form-control" name="password" id="password" placeholder="Enter your Password"/>
  110. </div>
  111. </div>
  112.  
  113.  
  114. <div class="form-group">
  115. <button class="btn btn-lg btn-primary btn-block" type="submit" name="submit" value="Submit">Sign in</button>
  116. </div>
  117.  
  118. </div> <!-- panel body -->
  119.  
  120. </form>
  121. </div> <!-- panel end -->
  122. </div>
  123.  
  124. </div> <!-- row end -->
  125.  
  126. </div> <!-- container end -->
  127.  
  128.  
  129. </body></html>
  130.  
  131.  
  132. <?php } ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement