程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> PHP編程 >> 關於PHP編程 >> PHP修改LDAP用戶密碼程序

PHP修改LDAP用戶密碼程序

編輯:關於PHP編程

 

ldap.php

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"

    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>

<title> Reset LDAP Password</title>

<style type="text/css">

dt{

    font-weight: bold;

}

</style>

</head>

<body>

<?php

/*

===========================================================   

    ldap.php    Zhu Weiwei

    Copyright © 2006-2008

    http://www.cncmm.com China. All Rights Reserved.

===========================================================

*/

 

$u   = $_REQUEST['u'];

$op  = $_REQUEST['op'];

$np1 = $_REQUEST['np1'];

$np2 = $_REQUEST['np2'];

$an  = $_REQUEST['an'];

if(!empty($an)){

    if( empty($u) or empty($op) or empty($np1) or empty($np2) ){

        $msg = "Some filed was empty!";

    }else{

        if( $np1 != $np2  ){

            $msg = "confirm password error!";

        }else{

            if($op == $np1){

               $msg = "new password can not be same as old password!";

            }else{

                $ldap_host = "domain.com";

                $ldap_port = 389;

                $base_dn   = "dc=domain,dc=com";

                $connect = @ldap_connect( $ldap_host, $ldap_port);

                if(!$connect){

                    $msg = "Could not connect to LDAP server";

                }else{

                    $user_dn   = sprintf("uid=%s,ou=Staff,dc=domain,dc=com",$u);

                    $user_pass = $op;

 

                    $bind = @ldap_bind($connect, $user_dn, $user_pass);

                    if(!$bind){

                        $msg = "old password error!";

                    }else{

                        $root_dn   = "cn=Manager,dc=domain,dc=com";

                        $root_pass = 'noPa$$w0rd#';

                        $bind = @ldap_bind($connect, $root_dn, $root_pass);

                        if(!$bind){

                            $msg = "Programe can not bind to LDAP server!";

                        }else{

                            $values["userPassword"][0] = "{md5}".base64_encode(pack("H*",md5($np1)));

                            $rs = @ldap_mod_replace($connect,$user_dn,$values);

                            if($rs){

                                $msg = "password modifed success!";

                            }else{

                                $msg = "password modifed failed!";

                            }

                        }

                    }

                }

                @ldap_close($connect);

            }

        }

    }

}

 

if(!empty($msg)){

    print("<h1>$msg</h1>");

}

?>

 

<form method="post" action="">

  <dl>

    <dt>User Id</dt>

    <dd>uid=<input type="text" name="u" size="16" />,ou=Staff,dc=domain,dc=cn</dd>

 

    <dt>Old Password</dt>

    <dd><input type="text" name="op" /></dd>

 

    <dt>New Password</dt>

    <dd><input type="text" name="np1" /></dd>

 

    <dt>Confirm Password</dt>

    <dd><input type="text" name="np2" /></dd>

    <dd><input type="submit" value="Submit" /></dd>

  </dl>

  <input type="hidden" name="an" value="submit" />

</form>

</body>

</html>

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved