PHP: Modify the LDAP User Password Program

Source: Internet
Author: User

 

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 ['any'];

If (! Empty ($ )){

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 = "cocould 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 ("

}

?>

 

<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>

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.