Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

Password reset – Disabled for LDAP accounts

Code for checking and blocking LDAP users to reset password.

/**
 * Checks whether a user is LDAP user and restricts to reset password.
 *
 * @param  bool   $allow    Whether the password can be reset.
 * @param  int    $user_id  The ID of the user.
 * @return bool|WP_Error
 */
function ldap_restrict_password_reset( $allow, $user_id ) {

    $user = get_user_by( 'id', $user_id );
    if ( ! empty( $user ) ) {
        $user_login   = stripslashes( $user->data->user_login );
        $user_email   = stripslashes( $user->data->user_email );

        // check if the user a LDAP user
        if( $user_email === '[email protected]' ) {
            return new WP_Error('no_password_reset', __('Password reset is not allowed for this LDAP user on this site.'));
        }
    }

    return $allow;
}
/* Filters whether the user's password can be reset. */
add_filter( 'allow_password_reset', 'ldap_restrict_password_reset', 10, 2 );

Note: Please add code to get and check if the user is a LDAP user or not.

=========================================================

These are some of the hooks that you can use to stop sending email and show error message.

/**
 * Fires before a new password is retrieved.
 *
 * @since 1.5.1
 *
 * @param string $user_login The user login name.
 */
do_action( 'retrieve_password', $user_login );

/**
 * Filter whether to allow a password to be reset.
 *
 * @since 2.7.0
 *
 * @param bool true           Whether to allow the password to be reset. Default true.
 * @param int  $user_data->ID The ID of the user attempting to reset a password.
 */
$allow = apply_filters( 'allow_password_reset', true, $user_data->ID );

if ( ! $allow )
    return new WP_Error('no_password_reset', __('Password reset is not allowed for this user'));
else if ( is_wp_error($allow) )
    return $allow;

Above is part of the code taken from wp-login.php file. http://wpseek.com/retrieve_password/

Related Posts:

  1. How to customise wp-login.php only for users who are setting a password for the first time?
  2. reset password link redirect to login page
  3. Is there anyway to get the inputted password string from the login form?
  4. wordpress login without password just email address (NO 2 factor authentication with email)
  5. Temporally disable password to login with empty password?
  6. Login form does not store/remember/suggest users password
  7. How can I redirect user after entering wrong password?
  8. Check for correct username on custom login form
  9. Custom login form
  10. Prevent wp_login_form() from redirecting to wp-admin when there are errors
  11. How do I change the language of only the login page?
  12. Disable WordPress 3.6 idle logout / login modal window / session expiration
  13. Avoid to load default WP styles in login screen
  14. How to fake a WordPress login?
  15. Can not login with correct username and password
  16. How can I add a custom script to footer of login page?
  17. How to keep always logged in development environment
  18. Add Confirm Password field in wp-login.php Password Reset page
  19. I want to disable E-Mail verifcation / activation when a user signs up for my WordPress site
  20. custom login page redirect to logged in user profile page
  21. How can I modify the default reset (lost) password email text?
  22. Action wp_login_failed not working if only one field is filled out
  23. Give visitor access to password protected page/post via external script
  24. Send reset password link to user from custom lost password form
  25. WordPress Login Footer URL
  26. Remove built in wordpress login and use only google auth
  27. Change Login Page for a Multisite Subsite
  28. Positioning the “Lost your password?” and “← Back to Site”
  29. send users logging in from wp-login.php directly to home page of site, rather than dashboard
  30. How can I retrieve the username and password from my WordPress installation?
  31. How to get login data (session) outside WordPress?
  32. password protect individual pages
  33. Problem with logging in WP users automatically
  34. How to determine if a user has not changed default generated password
  35. Add class to input form in login form
  36. Allow access to a page for admins only
  37. Customizing login error messages
  38. Customizing the WordPress login form
  39. Restricting frontend acess based on user role otherwise redirect to login form
  40. Right practice to edit WP reset password email
  41. how to restrict user login whenever if a user puts on hold by editing wp-login action?
  42. How do I force “users must be registered and logged in” on subsites?
  43. deny IPs from wp-login using .htaccess
  44. Passing username to login screen
  45. Login error redirecting to wp-login page
  46. How can I prevent my custom form from redirecting to wp-login?
  47. Private page protected with username and password
  48. How do I replace “Username” in the WordPress login form?
  49. Password protect media attachment – share across guests
  50. Custom Login iframe doesn’t work
  51. How to Get Logged-in to “Remote WP Site” from my local script (in Same Browser)?
  52. Replace dash with space in username on login
  53. Autologin only working the second time
  54. replace wp-login.php login forms via a hook & use custom forms with wp-login form validation
  55. Why wp_update_user doesn’t update user_activation_key on users with apostrophes in their email?
  56. Forgot Password/ Password Reset Page does not exist
  57. Correct passwords keep appearing as incorrect
  58. Forgot password needs to redirect from wp-login to a custom page
  59. Auto login between word press subdomain and a .net website
  60. Disabling standard registration login with username/email and password?
  61. Deep customization of wp-login.php
  62. How to change wordpress Log In text
  63. WordPress error on log out ‘Not Permitted’ and can’t log out
  64. Redirect wp-login
  65. How can I change the email sender name from wordpress to (myblogname) on the “lost password” email?
  66. Is wp_login_form secure on a non secure page?
  67. How to password-protect everything except the logo
  68. Is the login encrypted before it is sent? If so how to do I encrypt it the same way?
  69. Form Action submit over https
  70. Login and Forgot password in Lightbox
  71. Forcing frontend login with UI switch
  72. How can I password protect a WordPress site without requiring users to log in?
  73. Prevent display password on wp-login.php
  74. Password not resetting on wordpress?
  75. autocomplete=”off” WordPress Login
  76. Change default login auth
  77. WordPress not logged in locally with correct username and password
  78. WordPress SSL not working [closed]
  79. Where is the php file, that does the checks for login information?
  80. Can I protect a type of content site-wide with a single password?
  81. Password recovery URL has error – but not found in code or db
  82. Cannot Get User id after login success in file wp_login.php
  83. Alert Message through email or phone(Message)
  84. Moving from one host to another – cannot access the dashboard
  85. How are all users now set to inactive?
  86. I need to find which is the file that checks the DB for correct login (username, password)
  87. woocommerce store login not working at first time
  88. How do I change the language of the login page to Arabic?
  89. How do you implement a login feature on a WordPress site?
  90. How to add custom authentication to wordpress login and register
  91. Problem in auto login after registration
  92. Custom user roles are unable to login
  93. Using is_user_logged_in() to lock down whole site
  94. How to invalidate `password reset key` after being used
  95. Check for $ _POST fields in a POST method form
  96. Styling WordPress login page – Can I change the markup on the login page?
  97. Special link for no automatic login (no username and no password)
  98. WordPress password reset not working
  99. Modify wp-login.php Labels Conditionally Based On Referring URL
  100. Can’t login with any account – No error message shown
Categories login Tags login, password, wp-login-form
LaTeX for WordPress strips codes in loop
Co-authors plus problems with query_post

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress