How to change the password in ldap php: first find the form page "ldap.html"; then open the processing logic page "ldap.php"; finally modify the code to "$_POST["new_pass1"];if ( !$old_pass) {return...}".
The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer
php realizes the modification of ldap account password
Form page ldap.html
<html><body><form action="ldap.php" method="post">帐号名: <input type="text" name="acc_name"><br>旧密码: <input type="text" name="old_pass"><br>新密码: <input type="text" name="new_pass"><br> Again: <input type="text" name="new_pass1"><br><input type="submit"></form></body></html>
Processing logic ldap.php
<html> <body> <?php function ChangePass() { $acc_name = $_POST["acc_name"]; $old_pass = $_POST["old_pass"]; $new_pass = $_POST["new_pass"]; $new_pass1 = $_POST["new_pass1"];if (!$old_pass) {return "请输入旧密码。"; }if (!$new_pass || !$new_pass1) {return "请输入新密码。"; }if ($new_pass != $new_pass1) {return "新前后密码不一致!!!"; } $ldap_conn = ldap_connect("ldap://192.168.1.14:389");if (!$ldap_conn) {return "服务器连接失败!!!"; } ldap_set_option($ldap_conn, LDAP_OPT_PROTOCOL_VERSION, 3); $bind = ldap_bind($ldap_conn, "cn=admin,dc=xidea,dc=com", "jcd520");if (!$bind) {return "error"; } $dn = "ou=people,dc=xidea,dc=com"; $res = ldap_search($ldap_conn, $dn, "(uid=".$acc_name.")");if (!$res) {return "账号不存在1"; } $entry = ldap_first_entry($ldap_conn, $res);if (!$entry) {return "账号不存在"; } $attrs = ldap_get_attributes ( $ldap_conn, $entry); $db_pass1 = $attrs['userPassword'][0]; $db_pass2 = '{SHA}' . base64_encode(pack('H*', sha1($old_pass)));if ($db_pass1 != $db_pass2) {return "密码错误"; }return "suc"; $user_dn = ldap_get_dn($ldap_conn, $entry); $new["userPassword"] = '{SHA}' . base64_encode(pack('H*', sha1($new_pass))); ldap_modify($ldap_conn, $user_dn, $new); ldap_close($ldap_conn); }echo ChangePass();echo "<a href=\"ldap.html\">重新修改</a>" ?></body> </html>
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to change password in ldap php. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Dreamweaver Mac version
Visual web development tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

WebStorm Mac version
Useful JavaScript development tools

Zend Studio 13.0.1
Powerful PHP integrated development environment
