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>