How to change password in ldap php
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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

Working with database in CakePHP is very easy. We will understand the CRUD (Create, Read, Update, Delete) operations in this chapter.

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

To work on file upload we are going to use the form helper. Here, is an example for file upload.

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

Validator can be created by adding the following two lines in the controller.

Logging in CakePHP is a very easy task. You just have to use one function. You can log errors, exceptions, user activities, action taken by users, for any background process like cronjob. Logging data in CakePHP is easy. The log() function is provide

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c
