|
|
@ -1,3 +1,6 @@ |
|
|
|
import java.io.BufferedReader; |
|
|
|
import java.io.IOException; |
|
|
|
import java.io.StringReader; |
|
|
|
import java.math.BigInteger; |
|
|
|
import java.security.MessageDigest; |
|
|
|
import java.security.NoSuchAlgorithmException; |
|
|
@ -83,4 +86,25 @@ public class PasswordValidator { |
|
|
|
|
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
public static boolean isPwned(String password) { |
|
|
|
String sha1 = PasswordValidator.getSHA1Hash(password); |
|
|
|
if (sha1 != null) { |
|
|
|
String url = "https://api.pwnedpasswords.com/range/" + sha1.substring(0, 5); |
|
|
|
try { |
|
|
|
String result = HttpApi.sendHttpGETRequest(url); |
|
|
|
BufferedReader bufReader = new BufferedReader(new StringReader(result)); |
|
|
|
String line = null; |
|
|
|
while ((line = bufReader.readLine()) != null) { |
|
|
|
if (sha1.toUpperCase().endsWith(line.split(":")[0])) { |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
} catch (IOException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return false; |
|
|
|
} |
|
|
|
} |