ldap php修改密码的实现方法:首先找到表单页面“ldap.html”;然后打开处理逻辑页面“ldap.php”;最后修改代码为“$_POST["new_pass1"];if (!$old_pass) {return...}”即可。
本文操作环境:windows7系统、PHP7.1版,DELL G3电脑
php 实现修改 ldap 账号密码
表单页面 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>
处理逻辑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>
推荐学习:《PHP视频教程》
以上是ldap php怎么修改密码的详细内容。更多信息请关注PHP中文网其他相关文章!