Skip to content

Instantly share code, notes, and snippets.

@newyear2006
Created February 28, 2018 12:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save newyear2006/6301b442d7ff748796cecb949e4e1af8 to your computer and use it in GitHub Desktop.
Save newyear2006/6301b442d7ff748796cecb949e4e1af8 to your computer and use it in GitHub Desktop.
Powershell-Abfrage, ob Passwort sicher ist
Function Get-PwnedPasswordCounter ($password) {
# Hashstring erzeugen
$sha1=[System.Security.Cryptography.SHA1]::Create()
$sha1Hash=$sha1.ComputeHash([System.Text.Encoding]::UTF8.GetBytes($password))
$sha1HashString=[System.BitConverter]::ToString($sha1Hash).Replace('-','')
$hashPrefix=$sha1HashString.Substring(0,5)
$hashSuffix=$sha1HashString.Substring(5)
# pwnedpasswords-API anrufen
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$wr=Invoke-WebRequest -Uri "https://api.pwnedpasswords.com/range/$hashPrefix" -UseBasicParsing
# Ergebnis auswerten und Count ermitteln
If ($wr.StatusCode -eq 200) {
$regexPattern="(?<hash>$hashSuffix.*):(?<count>\d+)"
$parseRangeRegex=[regex]::new($regexPattern, [System.Text.RegularExpressions.RegexOptions]::Multiline -bor [System.Text.RegularExpressions.RegexOptions]::IgnoreCase)
$match=$parseRangeRegex.Match($wr.Content)
If ($match.Success) {
$match.Groups["count"].Value
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment