# take securestring and get the entered plain text password # we are using a securestring only to get a masked input box $BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($Password) $plain = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)
# separate the first 5 hash characters from the rest $first5hashChars,$remainingHashChars = $hash.Hash -split'(?<=^.{5})'
# send the first 5 hash characters to the web service $url = "https://api.pwnedpasswords.com/range/$first5hashChars" [Net.ServicePointManager]::SecurityProtocol = 'Tls12' $response = Invoke-RestMethod-Uri$url-UseBasicParsing
# split result into individual lines... $lines = $response-split'\r\n' # ...and get the line where the returned hash matches your # remainder of the hash that you kept private $filteredLines = $lines-like"$remainingHashChars*"
# return the number of compromises [int]($filteredLines-split':')[-1] }