Using PowerShell to check pwned passwords

Step 1: Install the required modules

Ensure you have the necessary PowerShell module installed. The script below installs a module that checks passwords against breached databases.

Install-Module -Name HaveIBeenPwned -Scope CurrentUser

Step 2: Hash the password before sending

To protect privacy, convert the password into a SHA1 hash.

$Password = "UserPassword123!"
$PasswordHash = (ConvertTo-SecureString -AsPlainText $Password -Force) | Get-FileHash -Algorithm SHA1

Step 3: Check against the breach database

Query the Have I Been Pwned API. The script below returns the number of times the password has appeared in breaches.

$PwnedCount = Invoke-RestMethod -Uri "https://api.pwnedpasswords.com/range/$($PasswordHash.Substring(0,5))"

Step 4: Alert the user if the password is compromised

If the password is found in the breach database, prompt a reset. The script below notifies users if their password is exposed.

if ($PwnedCount -gt 0) { Write-Host "Warning: This password has been compromised $PwnedCount times. Choose a new one!"
} else {
Write-Host "Password is safe."
}

FAQs

1. What is a "pwned" password?

A password found in a data breach is considered "pwned" and should be changed.

2. How do I check if a password is compromised using PowerShell?

Use the Have I Been Pwned API by running the script below:

Invoke-WebRequest -Uri "https://api.pwnedpasswords.com/range/5BAA6" -UseBasicParsing

3. Can I block users from using pwned passwords in AD?

Yes, use custom scripts to compare passwords against a breached password list and notify the users using breached passwords.

 
  • Step 1: Install the required modules
  • Step 2: Hash the password before sending
  • Step 3: Check against the breach database
  • Step 4: Alert the user if the password is compromised
  • FAQs

ADSelfService Plus trusted by

A single pane of glass for complete self service password management
Email Download Link