回 帖 发 新 帖 刷新版面

主题:高手帮我看看这段代码

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<head>
<title> Reset LDAP Password</title>
<style type="text/css">
dt{
   font-weight: bold;
}
</style>
</head>
<body>
<?php
/*
*PHP写的修改LDAP密码的小页面,要先通过用户cn获取到dn,然后通过dn修改用户的密码。
*/
 
if(isset($_REQUEST) && array_key_exists('an',$_REQUEST)){
$u  = $_REQUEST['u'];  //用户名
$op = $_REQUEST['op']; //旧密码
$np1 = $_REQUEST['np1'];
$np2 = $_REQUEST['np2'];
$an = $_REQUEST['an'];
}
 
if(!emptyempty($an)){
   if( emptyempty($u) or emptyempty($op) or emptyempty($np1) or emptyempty($np2) ){
       $msg = "Some filed was empty!";
   }else{
       if( $np1 != $np2 ){
           $msg = "新密码输入不一致!";
       }else{
           if($op == $np1){
              $msg = "新密码与旧密码相同,请重新输入!";
           }else{
               $ldap_host = "10.62.0.17";
               $ldap_port = 389;
               $base_dn  = "dc=domain,dc=com";
               $connect = ldap_connect( $ldap_host, $ldap_port);             //连接服务器
  if(!$connect){
                   $msg = "无法连接LDAP服务器";
               }else{
                         $user_pass = $op;
                         ldap_set_option($connect, LDAP_OPT_PROTOCOL_VERSION, 3);
                         ldap_set_option($connect, LDAP_OPT_REFERRALS, 0);
                         $uid=sprintf("uid=%s",$u);
                         $search=ldap_search($connect,$base_dn,$uid);  //根据uid获取到用户的信息
                         $dn=ldap_get_entries($connect,$search);
                         for ($i=0; $i<$dn["count"]; $i++)              //从获取到的数组取出用户dn,没有用户dn修改不了密码。
                         {
                              $user_dn= $dn[$i]["dn"];
                         }
                         $bind = ldap_bind($connect, $user_dn, $user_pass);       //登录验证
                        if(!$bind){
                              $msg = "旧密码不正确,请重新输入!";
                         }else{
                                 $values["userPassword"][0] = "{SHA}".base64_encode(pack("H*",sha1($np1)));  //密码sha1加密
                                 $rs = ldap_mod_replace($connect,$user_dn,$values);           //更新用户信息
                                if($rs){
                                         $msg="修改成功!";
                                 }else{
                                         $msg = "修改失败,请与XX联系!";
                                      }
                              }
 
                    }
                 ldap_close($connect);                                                      //关闭连接
                 }
            }
      }
}
 
if(!emptyempty($msg)){
   print("<h1>$msg</h1>");
}
?>
 
<form  method="post" action="">
 <dl>
   <dt>用户名</dt>
 <dd><input type="text" name="u"  /></dd>
 
   <dt>原密码</dt>
   <dd><input type="password" name="op" /></dd>
 
   <dt>新密码</dt>
   <dd><input type="password" name="np1" /></dd>
 
   <dt>确认新密码</dt>
   <dd><input type="password" name="np2" /></dd>
   <dd><input type="submit" value="确定" /></dd>
 </dl>
 <input type="hidden" name="an" value="submit" />
</form>
</body>
</html>
0

回复列表 (共3个回复)

沙发

你是专业编程还是业余的


板凳

业余


3 楼

在线博彩平台:www.pb258.com
在线博彩平台:www.jjxtech.com 
在线博彩平台:www.lcmty.com 
在线博彩平台:www.7macau.com
在线博彩平台:www.7macau.net
在线博彩平台:www.bp258.com
在线博彩平台:www.258bp.com
博狗:http://679.258bp.com
博狗:http://680.258bp.com
博狗:http://681.258bp.com
博狗:http://682.258bp.com
博狗:http://683.258bp.com
博狗:http://684.258bp.com
博狗:http://685.258bp.com
博狗:http://686.258bp.com
博狗:http://687.258bp.com
博狗:http://688.258bp.com
博狗:http://689.258bp.com
博狗:http://690.258bp.com
博狗:http://691.258bp.com
博狗:http://692.258bp.com
博狗:http://693.258bp.com
博狗合营:http://694.258bp.com
888真人:http://695.258bp.com
888真人:http://696.258bp.com
888真人:http://697.258bp.com
加百利:http://698.258bp.com
加百利:http://699.258bp.com 
必威:http://700.258bp.com
必威:http://701.258bp.com
必威:http://702.258bp.com
必威:http://703.258bp.com
必威:http://704.258bp.com
必威:http://705.258bp.com
必威:http://706.258bp.com
必威合营:http://707.258bp.com
新博:http://708.258bp.com
鸿运国际:http://709.258bp.com
鸿运国际:http://710.258bp.com
鸿运国际:http://711.258bp.com
新橙娱乐:http://712.258bp.com
新橙娱乐:http://713.258bp.com
新橙娱乐:http://714.258bp.com
新橙娱乐:http://715.258bp.com
新橙娱乐合营:http://716.258bp.com
乐虎:http://717.258bp.com
乐虎:http://718.258bp.com
乐虎:http://719.258bp.com
乐虎:http://720.258bp.com
乐虎:http://721.258bp.com
乐虎:http://722.258bp.com
亚虎:http://723.258bp.com
亚虎:http://724.258bp.com
亚虎:http://725.258bp.com
龙8国际娱乐:http://726.258bp.com
龙8国际娱乐:http://727.258bp.com
龙8国际娱乐:http://728.258bp.com
龙8国际娱乐:http://729.258bp.com
龙8国际娱乐:http://730.258bp.com
龙8国际娱乐:http://731.258bp.com
必博:http://2274.bbo233.com
必博:http://2274.bbo998.com

我来回复

您尚未登录,请登录后再回复。点此登录或注册