Last active
August 15, 2024 15:15
-
-
Save eosfor/1563a8ca6e6ea0a3a1a6a8909faf2b90 to your computer and use it in GitHub Desktop.
Test passwords against https://haveibeenpwned.com/Passwords
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Test-Password { | |
[CmdletBinding()] | |
param ( | |
[Parameter(ValueFromPipeline=$true)] | |
[string]$Password | |
) | |
begin { | |
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 | |
} | |
process { | |
$passwordBytes = [System.Text.Encoding]::UTF8.GetBytes($Password) | |
$sha1 = New-Object System.Security.Cryptography.SHA1Managed | |
$hash = $sha1.ComputeHash($passwordBytes) | |
$hexHash = [System.BitConverter]::ToString($hash).Replace("-", "") | |
$first5 = $hexHash.Substring(0,5) | |
$rest = $hexHash.Substring(5) | |
$content = (Invoke-WebRequest https://api.pwnedpasswords.com/range/$first5).Content | |
$content.Split() | where {$_ -like "$rest*"} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment