Created
February 28, 2018 12:56
-
-
Save newyear2006/6301b442d7ff748796cecb949e4e1af8 to your computer and use it in GitHub Desktop.
Powershell-Abfrage, ob Passwort sicher ist
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 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
based on https://github.com/Philo/IsItPwned/blob/master/src/PwnedPasswordClient.cs
sowie https://www.troyhunt.com/ive-just-launched-pwned-passwords-version-2/