Skip to content

Instantly share code, notes, and snippets.

@eosfor
Last active July 11, 2018 23:42
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eosfor/1563a8ca6e6ea0a3a1a6a8909faf2b90 to your computer and use it in GitHub Desktop.
Save eosfor/1563a8ca6e6ea0a3a1a6a8909faf2b90 to your computer and use it in GitHub Desktop.
Test passwords against https://haveibeenpwned.com/Passwords
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