hello I would like to make users change the password of the accounts without receiving the email since it is an internal server how can I change the password of ldap with laravel and php
My Answer:
You can change the password of an LDAP user using the `ldap_modify` function in PHP. Here is an example code snippet using Laravel:
php
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;
// Get the LDAP connection
$ldapconn = ldap_connect('ldap://your-ldap-server');
ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3);
// Bind to the LDAP server
$ldapbind = ldap_bind($ldapconn, 'cn=admin,dc=example,dc=com', 'admin_password');
// Get the user's DN
$userDn = 'uid=user,ou=users,dc=example,dc=com';
// Generate a new password
$newPassword = 'new_password';
// Update the user's password
$entry = [
'userPassword' => Hash::make($newPassword)
];
if (ldap_modify($ldapconn, $userDn, $entry)) {
echo "Password updated successfully";
} else {
echo "Failed to update password";
}
// Close the LDAP connection
ldap_close($ldapconn);
Make sure to replace the LDAP server details, admin credentials, user DN, and new password with your actual values. Also, ensure that the `Hash::make` function is compatible with your LDAP server's password hashing algorithm.
Rate this post
5 of 5 based on 2164 votesComments