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中文網其他相關文章!