1. Home
  2. WordPress Tutorials
  3. How to Completely Force Logout All Users in WordPress
Experience Faster, Secure and Eco-Friendly Web Hosting for your Website or Blog. Learn More.


How to Completely Force Logout All Users in WordPress

Do you want to be able to force log out all of your users in WordPress? It’s very common for users to not log out by choice. In fact, most users think logging in is quite annoying and actively try to avoid it. This is extremely troublesome when you have added new features to your website, which may require users to log back in.

WordPress security is a major concern for any web developer in today’s world. Brute force attacks, in particular, make it very easy to get access to a user account. Attacks can happen at any time and it can be quite difficult to know which accounts have become compromised. Thus, you can force log out every account to be safe. Today, I will demonstrate how to completely force log out every user in WordPress.

Why Forced Logouts Are a Good Thing

Many websites launch new additions for visitors who have a user account along with exclusive features for them. Visitors who sign up for accounts will be more likely to return and view your new content regularly. For this reason, it is important to give them additional features to help them enjoy your content. Unfortunately, as I mentioned before, users do not like to log out of their accounts which makes it increasingly difficult for features to be properly added to all of your accounts.

Keep in mind that user accounts are very different from membership and pay-per-view websites. Membership or pay-per-view websites need a different tutorial to add this feature to their websites. In fact, the plugin you chose to use to create your membership or pay-per-view website should have a force logout option built in. The feature is needed because users may be sharing their account with their friends and family, which allows a lot of people to view your paid content for free.

How to Completely Force Logout All Users in WordPress

Today, I will demonstrate how to completely force log out every user in WordPress. Before beginning this tutorial, make sure you have access to your cPanel. The login information is provided to you by your web host when you create an account. This tutorial focuses on editing the wp-config file, which stores all of the settings for your website. It is an extremely vital file and you should make a backup of your website before beginning.

Let’s start by logging into the cPanel and clicking on the File Manager option. The File Manager will allow you to access all of the files related to your website.

Click on the File Manager option.

You need to locate your wp-config.php file. Click on the public_html directory. Right-click on the wp-config.php file and select the Edit option.

Select the Edit option.

A pop-up window will show up. This box will warn you to create a backup of your files before editing anything. This will ensure that you can revert your website back to when it was working if something goes wrong. Click on the “Edit” button. A new tab will open containing all of the code from the file.

Click on the "Edit" button.

Skim through your wp-config.php file until you find a large block of code that resembles the following lines:

define(‘AUTH_KEY’, ‘vijctezdmejlitv5i8iwp132xxp2x3dj2ly0pckyddqgxdizsp3bigu2r06i2txe’);
define(‘SECURE_AUTH_KEY’, ‘7tlz4kt9vzxfajparqkqnui5sfcsqloapcbon4bshft1vwe8tthuszssz1c22oxn’);
define(‘LOGGED_IN_KEY’, ‘elzqynmr8tpwrtdtjys3vj5xkzop1ytm3ptacvgh2lsa7zvlgh22m3slgo7gadag’);
define(‘NONCE_KEY’, ‘vfu9c4fg3rmjlrpoikhmjtlegsxcf6lbamgawwsztnokb3rxfiothxdun1csgubm’);
define(‘AUTH_SALT’, ‘3gnpnbkgzm42ajsseh8fiknvgir3cjikknjsnhhwaukolzio5f9r8n4iw81hj8ab’);
define(‘SECURE_AUTH_SALT’, ‘etl64f2tnsgv22pgm6oigviu6mmtswqcoanktykaoowyallsxkgmnla0rphkqivo’);
define(‘LOGGED_IN_SALT’, ‘pw9ndaod8jsonqyhio0oudfanvbuy4fivtmddkkvrmuhac3bxcaj640zvdhdajpq’);
define(‘NONCE_SALT’, ‘u9p3i1nndqbrcd7davbgmcotiuoh0qeenfoldam0qrexjovm42h7plb5zop7uo7c’);

These lines of code are authentication keys and salt. Authentication keys will improve the encryption of your website. Encryption protects important information from hackers and other groups that may be interested in such information.

When these keys are changed, all users will be forced to log out. Of course, coming up with auth keys is not easy and can pose security risks if they are not complex enough. Thankfully, the WordPress salt generator does all of the work for you. Every time you open the salt generator, unique authentication keys are generated. Copy and paste these newly generated keys into your wp-config.php file and replace the old ones.

opy and paste these newly generated keys.

Once you have inserted the code into the wp-config.php file, click on the “Save Changes” button to finish.

Click on the "Save Changes" button.

Congratulations, all users will be logged out and will be forced to log back in. You must repeat these steps every time you would like to force a log out for all of your users. The process only takes a few minutes at most. Keep in mind users do not like to be logged out and you should have a good reason for doing this.

Keep Your User Accounts Safe and Up to Date

Signing up for accounts generally involves giving a website your email address. Email addresses are the target of many cyber attacks on smaller websites. Email addresses are essential to accessing other websites. Other websites may contain personal information like home address and credit card information. With an email address in hand, hackers will be able to use brute force to guess the password.

Brute force attacks are even easier when visitors have accounts with weak passwords in place. For example, imagine a WordPress account with the password “WordPress” or the famed “password” password. These situations will never exist if you enforce visitors to create an account with a strong password. Another method is to force users to regularly change their password. This will ensure that they cannot continue to use the same weak password.

Have you had any security situations occur because of weak passwords? Do you think users will be angry if they have to log in often?

Author: Ron Helms

I currently work for GreenGeeks as a Support Technician. My primary roles are supporting our VPS and Dedicated server clients, as well as performing site migrations. With experience in the web hosting industry since 2009, there is rarely a question I can’t help answer. In my spare time, I enjoy gaming and working on cars as an automotive enthusiast.

Updated on January 10, 2018

Was this article helpful?

Related Articles

Add A Comment