|
|
@ -1,3 +1,6 @@ |
|
|
|
import java.math.BigInteger; |
|
|
|
import java.security.MessageDigest; |
|
|
|
import java.security.NoSuchAlgorithmException; |
|
|
|
import java.util.regex.Pattern; |
|
|
|
|
|
|
|
public class PasswordValidator { |
|
|
@ -54,4 +57,30 @@ public class PasswordValidator { |
|
|
|
public void setRequireDigit(boolean requireDigit) { |
|
|
|
this.requireDigit = requireDigit; |
|
|
|
} |
|
|
|
|
|
|
|
public static String getSHA1Hash(String input) { |
|
|
|
if (input.length() > 0) { |
|
|
|
try { |
|
|
|
MessageDigest md = MessageDigest.getInstance("SHA-1"); |
|
|
|
byte[] messageDigest = md.digest(input.getBytes()); |
|
|
|
|
|
|
|
// Convert byte array into signum representation |
|
|
|
BigInteger no = new BigInteger(1, messageDigest); |
|
|
|
|
|
|
|
// Convert message digest into hex value |
|
|
|
StringBuilder hashtext = new StringBuilder(); |
|
|
|
hashtext.append(no.toString(16)); |
|
|
|
|
|
|
|
// Add preceding 0s to make it 32 bit |
|
|
|
while (hashtext.length() < 32) { |
|
|
|
hashtext.insert(0, "0"); |
|
|
|
} |
|
|
|
return hashtext.toString(); |
|
|
|
} catch (NoSuchAlgorithmException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return null; |
|
|
|
} |
|
|
|
} |