When a WordPress site is hacked, most of the attention goes to removing malicious code. That’s important, but it’s not the end of the job. If the attacker had access to your files or database, they could have read every secret stored there. Database passwords, API keys for payment gateways, SMTP credentials, cloud storage keys, licence keys. Any of those can be used again later, even after the malware is gone. Knowing when and how to rotate WordPress salts, passwords and keys is the part of recovery that keeps the attacker out for good.
I’ve seen sites cleaned perfectly, only to be reinfected a week later because the attacker still had the database password and the server accepted remote connections. I’ve also seen a client’s email service account used to send phishing emails, months after a hack, because the SMTP API key had been copied from a plugin’s settings.
Rotating secrets means replacing every credential that might have been exposed with a new one, and making sure the old one no longer works. It’s methodical work and it’s easy to miss something, so a checklist helps.
When to rotate
Rotate secrets after any incident where an attacker could have:
- Read files on the server, including wp-config.php
- Accessed the database, directly or through a vulnerability
- Logged into WordPress as an administrator
- Accessed the hosting control panel, SFTP or SSH
In practice, that covers almost every real compromise. If malicious PHP code ran on your server, assume it could read anything the web server user could read.
It’s also good practice after a staff member or agency with privileged access leaves, and periodically as general hygiene.
Do it after cleanup, not before
The order matters. If you rotate secrets while malicious code is still on the server, the attacker can simply read the new ones. Clean the site first, close the vulnerability that let them in, then rotate.
The exception is access that lets the attacker interfere with cleanup, such as hosting panel or SSH access. Change those first, so they can’t watch or undo your work.
A practical sequence:
- Change hosting control panel, SSH and SFTP credentials.
- Clean the site and patch the entry point.
- Rotate WordPress salts and the database password.
- Reset WordPress user passwords and revoke application passwords.
- Rotate third-party API keys and service credentials.
- Verify old credentials no longer work.
Hosting and server access
Start with whatever gives the deepest control.
- Hosting control panel. Change the password and enable two-factor authentication if it’s available. Check for any additional users that shouldn’t be there.
- SSH. Review authorized_keys for every system user. Remove keys you don’t recognise. Consider generating new keys for legitimate users if you suspect private keys were exposed on a compromised machine.
- SFTP and FTP. Change passwords. If plain FTP is still enabled, turn it off and use SFTP only.
- Root or sudo access. On a VPS, check for new users in /etc/passwd and unexpected entries in sudoers.
WordPress salts and keys
The authentication keys and salts in wp-config.php are used to sign login cookies. If an attacker knows them, they can potentially forge cookies. Changing them invalidates every existing login session, forcing everyone, attackers included, to log in again.
You can generate fresh values from the WordPress.org secret key service or with WP-CLI:
That command replaces all eight keys and salts with new random values. Everyone, including you, will be logged out immediately.
If you manage salts outside wp-config.php, for example in environment variables, update them there instead.
The database password
The database password lives in wp-config.php in plain text, so any attacker who could read files has it. If your database accepts connections from outside the server, that’s a direct way back in.
To change it:
- Create a new strong password.
- Update the database user’s password in your hosting panel, or with SQL:
- Update DB_PASSWORD in wp-config.php immediately afterwards.
- Load the site to confirm it connects.
There will be a few seconds of downtime between steps 2 and 3. On busy sites, prepare the wp-config.php change in advance so you can save it immediately.
While you’re at it, check that the database user only connects from localhost or your application server, not from any host. A database user allowed to connect from “%” is an unnecessary risk.
WordPress user passwords
Reset passwords for every user with publishing or administrative rights. For subscribers and customers on a store or membership site, it depends on what the attacker could access. If they had database access, they could have copied password hashes. Modern WordPress hashes are slow to crack, but weak passwords will still fall.
For administrators and editors, force a reset. For large customer bases, consider forcing a reset at next login and notifying users, especially if personal data may have been exposed. In some jurisdictions, notification may be a legal requirement.
Also remove any users you don’t recognise. Attackers often create backdoor administrator accounts with plausible names like “wpadmin” or “support”.
Application passwords
Application passwords are separate from the main password and survive a password reset. Check every administrator profile and revoke any you don’t recognise. Revoke the ones you do recognise too, then create new ones for the tools that need them. You can list them with WP-CLI:
Third-party API keys
This is where most people miss things. Go through every plugin with settings that include a key, token or password. Common ones:
- SMTP and email services. SendGrid, Mailgun, Postmark, Amazon SES, Brevo.
- Payment gateways. Stripe, PayPal, Razorpay and others. Rotate secret keys and webhook signing secrets.
- Cloud storage. S3, Backblaze, Google Cloud credentials used by backup or media offload plugins.
- CRM and marketing tools. Mailchimp, HubSpot, ActiveCampaign.
- Maps and other Google APIs. Restrict them by referrer as well as rotating.
- CDN and DNS. Cloudflare API tokens used by caching or DNS plugins.
- Licence keys for premium plugins. These are lower risk, but some vendors let you regenerate them.
A quick way to find stored secrets is to search the options table for likely terms:
That returns a lot of false positives, but it also surfaces settings you’d forgotten about.
For each service, generate a new key in the provider’s dashboard, update it in WordPress, test that the integration still works, then revoke the old key. Don’t skip the revoke step. A new key is useless if the old one still works.
Check the providers for misuse
While you’re in each provider’s dashboard, look for signs the old key was used. Email services show sending logs. Payment gateways show API activity. Cloud storage shows access logs if they were enabled. If you see activity you can’t explain, you may have a wider incident to deal with, such as a data breach or abuse of your email reputation.
Constants and environment files
Some secrets live outside the database, in wp-config.php constants or .env files. Search for them:
| <code>grep -nE "define(s*'[A-Z_]*(KEY | SECRET | TOKEN | PASS)" wp-config.php</code> |
|---|
Rotate each one you find.
Verify the old credentials are dead
The last step is the one that makes the rest count. For each credential, confirm the old one no longer works:
- Try logging in to SFTP with the old password.
- Check that the old API key returns an authentication error.
- Confirm old login sessions were ended.
Document what you rotated and when. If the attacker returns, you’ll know which credentials were already changed and can focus elsewhere.
Make the next rotation easier
Rotating secrets after an incident is stressful because it’s usually done in a hurry with no list. A few habits make it much smoother:
- Keep an inventory of every integration and where its credentials are stored.
- Use a password manager for all credentials, with notes on where each one is used.
- Prefer restricted API keys, such as send-only keys for email or keys limited to specific permissions, so a leaked key can do less.
- Store secrets in environment variables or constants rather than plugin settings where possible, so they aren’t sitting in the database.
The best time to build that inventory is now, while nothing is on fire.
Don’t forget the people who reset things for you
If an agency, host or freelancer helped with the cleanup, they now know some of your new credentials too. That’s usually fine, but note it in your access inventory and include them in the next offboarding pass when their work is finished. If you remember nothing else, rotate WordPress salts and every stored credential after any compromise, even one that looks minor.
Frequently asked questions
Will shuffling salts break anything?
It logs everyone out and invalidates password reset links in progress. Some plugins store data encrypted with salts, which may need resaving. Otherwise, it’s safe.
Do I need to tell customers about a hack?
If personal data may have been accessed, data protection laws in many countries require notifying authorities and affected individuals within a set time. Get advice specific to your jurisdiction.
How often should I rotate secrets without an incident?
Annually is reasonable for most small sites, plus whenever someone with access leaves. High-security sites rotate more often, ideally with automation.
Is changing the admin password enough?
No. It’s one of many secrets. Database passwords, salts and API keys can all give an attacker a way back in even after the admin password changes.




