PHP Modify LDAP user password Program _php tutorial

Source: Internet
Author: User
Tags ldap
ldap.php

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

Reset LDAP Password

/*

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

ldap.php Zhu Weiwei

copyright©2006-2008

Http://www.cncmm.com China. All rights Reserved.

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

*/

$u = $_request[' u '];

$op = $_request[' op '];

$NP 1 = $_request[' np1 ');

$NP 2 = $_request[' np2 ');

$an = $_request[' an '];

if (!empty ($an)) {

if (empty ($u) or empty ($op) or empty ($NP 1) or Empty ($NP 2)) {

$msg = "Some filed was empty!";

}else{

if ($NP 1! = $NP 2) {

$msg = "Confirm Password error!";

}else{

if ($op = = $np 1) {

$msg = "New password can not is 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$ $w 0rd# ';

$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 ($NP 1)));

$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 ("

$msg

");

}

?>

http://www.bkjia.com/PHPjc/478567.html www.bkjia.com true http://www.bkjia.com/PHPjc/478567.html techarticle 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 ti ...

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.