};
/**
- * Minimum password length
+ * Hard-coded minimum password length
*/
private static final Integer PASSWORD_MINIMUM_LENGTH = 5;
* @return Strength of password
*/
public static double calculatePasswordScore (final String password) {
- // Log message
- System.out.println(UserUtils.class.getSimpleName() + ".calculatePasswordScore: password=" + password + " - CALLED!"); //NOI18N
-
// Should not be null
if (null == password) {
// Throw NPE
//password length
score += password.length() * calculateEntropyFactor(password) / 100;
- // Log message
- System.out.println(UserUtils.class.getSimpleName() + ".calculatePasswordScore: score=" + score + " - after length"); //NOI18N
-
//password has 3 numbers
if (ifRegExFoundInString("(.*[0-9].*[0-9].*[0-9].*)+", password)) { //NOI18N
score += 5;
}
- // Log message
- System.out.println(UserUtils.class.getSimpleName() + ".calculatePasswordScore: score=" + score + " - after 3 numbers"); //NOI18N
-
//password has 2 symbols
if (ifRegExFoundInString("(.*[!,@,#,$,%,^,&,*,/,?,_,~,=,.,-,;,:].*[!,@,#,$,%,^,&,*,/,?,_,~,=,.,-,;,:].*)+", password)) { //NOI18N
score += 5;
}
- // Log message
- System.out.println(UserUtils.class.getSimpleName() + ".calculatePasswordScore: score=" + score + " - after 2 symbols"); //NOI18N
-
//password has Upper and Lower chars
if (ifRegExFoundInString("(.*[a-z].*[A-Z])|([A-Z].*[a-z].*)+", password)) { //NOI18N
score += 10;
}
- // Log message
- System.out.println(UserUtils.class.getSimpleName() + ".calculatePasswordScore: score=" + score + " - after upper/lower"); //NOI18N
-
//password has number and chars
if (ifRegExFoundInString("(.*[a-zA-Z].*)+", password) && ifRegExFoundInString("(.*[0-9].*)+", password)) { //NOI18N
score += 15;
}
- // Log message
- System.out.println(UserUtils.class.getSimpleName() + ".calculatePasswordScore: score=" + score + " - after number+chars"); //NOI18N
-
//password has number and symbol
if (ifRegExFoundInString("(.*[!,@,#,$,%,^,&,*,/,?,_,~,=,.,-,;,:].*)+", password) && ifRegExFoundInString("(.*[0-9].*)+", password)) { //NOI18N
score += 15;
}
- // Log message
- System.out.println(UserUtils.class.getSimpleName() + ".calculatePasswordScore: score=" + score + " - after number+symbol"); //NOI18N
-
//password has char and symbol
if (ifRegExFoundInString("(.*[!,@,#,$,%,^,&,*,/,?,_,~,=,.,-,;,:].*)+", password) && ifRegExFoundInString("(.*[a-zA-Z].*)+", password)) { //NOI18N
score += 15;
}
- // Log message
- System.out.println(UserUtils.class.getSimpleName() + ".calculatePasswordScore: score=" + score + " - after char+symbol"); //NOI18N
-
//password is just numbers or chars
if (ifRegExFoundInString("^[a-zA-Z]+$", password) || ifRegExFoundInString("^[0-9]+$", password)) { //NOI18N
score -= 10;
}
- // Log message
- System.out.println(UserUtils.class.getSimpleName() + ".calculatePasswordScore: score=" + score + " - after number/char"); //NOI18N
-
// Larger than 100 is not allowed
score = Math.max(Math.min(score, 100.0f), 0.0f);
- // Log message
- System.out.println(UserUtils.class.getSimpleName() + ".calculatePasswordScore: score=" + score + " - EXIT!"); //NOI18N
-
// Return it
return score;
}
/**
* Checks if password from container matches the updatedUser's password
* <p>
- * @param container Container holding user instance and unencrypted password
+ * @param container Container holding user instance and clear-text
+ * password
* @param updatedUser Updated user instance from database
* <p>
* @return Whether the password matches
/**
* Checks if direct password the updatedUser's password
* <p>
- * @param unencryptedPassword Unencrypted (direct) password
- * @param updatedUser Updated user instance from database
+ * @param unencryptedPassword Clear-text (direct) password
+ * @param updatedUser Updated user instance from database
* <p>
* @return Whether the password matches
*/
* Checks if the regular expression is found in given string
* <p>
* @param pattern Regular expression
- * @param str String
+ * @param str String
* <p>
* @return Whether it is found
*/
*/
private UserUtils () {
}
+
}