• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
NameHero® Blog

NameHero® Blog

Web Hosting Tips & Resources From NameHero

  • AI Agents
    • OpenClaw
    • Claude Code
    • n8n
    • Hermes Agent
    • Open WebUI
    • Docker
  • Hosting
    • Web Hosting
    • WordPress Hosting
    • WooCommerce Hosting
    • Enterprise Hosting
    • Email Hosting
    • HeroicGuard
    • GPU Hosting
    • Website Builder
  • VPS
    • Managed VPS
    • Unmanaged VPS
    • Flex VPS
  • Reseller
  • Gaming
  • Domains
  • Account
  • Blog Home
  • Categories
  • Authors

How To Enable Password Resets ONLY For Administrators

Bhagwad Park

Published on: October 11, 2021

Categories: WordPress 0

If you’ve run a website for a while, you know that you can sometimes get emails from hackers trying to use the “password reset” button. While this shouldn’t work because they don’t have access to your email (hopefully!), it can still be annoying to sift through the spam, and in general, it causes additional workload on your server. My preferred technique to deal with this problem is to mask the wp-login.php page itself. But if you have a bunch of users, you don’t want to confuse them with alternate login pages. One way out of this is to disable the password reset link for all users except the administrators. This way, you can reset their password manually when necessary.

Now obviously this won’t work if your site has hundreds or thousands of visitors. You can’t be expected to manually reset people’s passwords all the time. But if you have just a handful of users (or even one!), then a password reset will happen pretty infrequently, and it shouldn’t be a problem. So let’s see how to do this.

The Code for Disabling Password Resets for Non-Admins

While there are plugins that can do the job, why add a new plugin to your site when you can just add some code manually? I recommend creating your own custom plugin for code. We have a nice knowledgebase article on using a custom plugin for code insertion on WordPress, so I suggest you follow that detailed tutorial. Alternatively, you can just insert the code into the “functions.php” file of your WordPress theme. But it’s a lot more dangerous to do this since if you break something, you can crash your site. With plugins on the other hand, it’s easier to revert the changes, and WordPress itself has built-in mechanisms to safeguard you from self-destructing.

Here’s the code to insert:

// Enable password reset only for admin
function enable_admin_password_reset($allow, $user_id) {
    if (user_can( $user_id, 'manage_options' ))
        return true;
      
	return false;
}
add_filter ( 'allow_password_reset', 'enable_admin_password_reset', 10, 2 );

This will disable the password reset functionality for all users that don’t have administrator permissions. For example, here is what a standard user will see if they try and reset the password using the “Forgot Password?” text link on the login screen:

Disabling Password Reset in WordPress for Non-Admin Users
Disabling Password Reset in WordPress for Non-Admin Users

You can see that it says “Password reset is not allowed for this user”. Perfect!

So How Do We Reset Passwords Then?

Administrators can always just create a new password for the user and send it to them via the “Users” screen. The downside might be that they’ll have to transmit the new password over an insecure channel like e-mail. Alternatively, they can reset the password to something basic and require the user to log in and change it to something harder to guess.

Admins can also use the backend PHP database to reset the passwords of everyone, including themselves. Here’s a tutorial on resetting it via the PHP backend. This method works even if you’ve been locked out of the admin screen and can’t reset anything because it changes the password directly from the backend. It just requires a few more steps, thanks to the hashing algorithm that MySQL uses to store passwords.

Hardening WordPress is a Constant Endeavor

It requires ongoing vigilance to secure your site from hackers. Here are some Cloudflare Page Rules to get you started, along with a section on Rate Limiting, and more on the NameHero blog. All these methods contribute to keeping WordPress safe from spam and attacks, and you must always monitor their effectiveness.

Bhagwad Park Profile Picture
Bhagwad Park

I’m a NameHero team member, and an expert on WordPress and web hosting. I’ve been in this industry since 2008. I’ve also developed apps on Android and have written extensive tutorials on managing Linux servers. You can contact me on my website WP-Tweaks.com!

Related Posts

Blogger vs. WordPress: Which One to Use?

Let's compare WordPress and Blogger across five key areas. Then, we'll show you how to set up a professional blog with WordPress.

How To Start A Newsletter In WordPress

Check out our complete guide on why and how you should start your own newsletter in WordPress.

What Is Self-Hosted WordPress?

In this post, we’ll differentiate self-hosted WordPress from WordPress.com, and discuss the benefits of the former.

Joomla vs. WordPress: Which One Is Better?

In this post, we’ll consider five differences between Joomla and WordPress and how you might go forward with setting up a WordPress website.

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Follow & Subscribe

Exclusive promos, content and more!


Most Popular Posts

NameHero’s Recommended WordPress Plugin and Theme Setup

WordPress Hosting vs. Web Hosting – What’s The Difference?

How To Increase The InnoDB Buffer Pool Size

How To Fix A Stuck All-in-One WP Migration Import

How To Add A Subdomain In Cloudflare

Top Categories

  • WordPress
  • WordPress Tutorials
  • OpenClaw Hosting
  • Enterprise Hosting
  • WooCommerce
  • Web Hosting
  • Resellers
  • Website Security
  • Website Development
  • Website Performance
  • VPS Hosting
  • SEO Tips
  • Announcements
  • Domain Registration
NameHero

NameHero® proudly provides web hosting to over 40,000 customers with 99.9% uptime to over 750,000 websites.

  • Master Card
  • Visa
  • American Express
  • Discover
  • Paypal
Products
  • Web Hosting
  • Managed VPS Hosting
  • Unmanaged VPS Hosting
  • Flex VPS Hosting
  • WordPress Hosting
  • WooCommerce Hosting
  • Reseller Hosting
  • Enterprise Hosting
  • GPU Hosting
  • Email Hosting
  • HeroicGuard
  • Domains
  • Website Builder
  • AI Agent Hosting
Help & Support
  • NameHero Blog
  • NameHero Gaming Blog
  • Support
  • Help Center
  • Migrations
  • Affiliates
  • Gaming Affiliates
  • Call 1-855-984-6263
Company
  • About Us
  • Contact Sales
  • Reviews
  • Uptime
  • We're Hiring

Copyright © 2026 Name Hero, LLC. All rights reserved.
NameHero® is a registered trademark.

  • Privacy Policy
  • Terms of Use
  • Acceptable Use Policy
  • Payment Policy
  • DMCA