Here is the code I use, you can tweak it to fit with your standards.
public class ValidationUtils {
private final static String EMAIL_VALIDATION_REGEX = "[a-zA-Z0-9!#$
%&'*+/=?^_`{|}~-]+(?:\\.[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-zA-
Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-
zA-Z0-9])?";
private static final int PASSWORD_LEVEL_VERYWEAK = 0;
private static final int PASSWORD_LEVEL_WEAK = 1;
private static final int PASSWORD_LEVEL_MEDIOCRE = 2;
private static final int PASSWORD_LEVEL_STRONG = 3;
private static final int PASSWORD_LEVEL_VERYSTRONG = 4;
public ValidationUtils(){
}
public static boolean validateEmail(String text) {
if (text.matches(EMAIL_VALIDATION_REGEX)) {
return true;
}
else
return false;
}
public static int CheckPasswordStrength(String passwd) {
boolean upper = false,
lower = false,
numbers = false,
special = false;
int intScore = 0, length = 0;
if (passwd == null)
return PASSWORD_LEVEL_VERYWEAK;
// PASSWORD LENGTH
length = passwd.length();
if (length < 5) // length 4 or less
{
intScore = (intScore + 3);
} else if (length > 4 && passwd.length() < 8) // length
between 5 and 7
{
intScore = (intScore + 6);
} else if (
length > 7 && passwd.length() < 16) //
length between 8 and 15
{
intScore = (intScore + 12);
} else if (length > 15) // length 16 or more
{
intScore = (intScore + 18);
}
// LETTERS
if (passwd.matches(".*[a-z]+.*"))
{
intScore = (intScore + 1);
lower=true;
}
if (passwd.matches(".*[A-Z]+.*"))
{
intScore = (intScore + 5);
upper=true;
}
// NUMBERS
if (passwd.matches(".*[0-9]+.*"))
{
intScore = (intScore + 5);
numbers=true;
}
if (passwd.matches(".*[0-9].*[0-9].*[0-9].*"))
intScore = (intScore + 3);
// SPECIAL CHAR
if (passwd.matches(".*[:,!,@,#,$,%,^,&,*,?,_,~]+.*"))
{
intScore = (intScore + 5);
special=true;
}
if (passwd.matches(".*[:,!,@,#,$,%,^,&,*,?,_,~].*[:,!,@,#,
$,%,^,&,*,?,_,~].*"))
intScore = (intScore + 3);
// COMBOS
if (upper && lower ) // [verified] both upper and lower
case
{
intScore = (intScore + 2);
}
if ((upper || lower )
&& numbers ) // [verified] both letters
and numbers
{
intScore = (intScore + 2);
}
if ((upper || lower )
&& numbers
&& special) // [verified] letters,
numbers, and special characters
{
intScore = (intScore + 2);
}
if (upper && lower && numbers &&
special ) // [verified] upper, lower, numbers, and
special characters
{
intScore = (intScore + 2);
}
//System.out.println("Mdp: "+passwd+" Score :" +intScore);
if (intScore < 16)
return PASSWORD_LEVEL_VERYWEAK;
else if (intScore > 15 && intScore < 25)
return PASSWORD_LEVEL_WEAK;
else if (intScore > 24 && intScore < 35)
return PASSWORD_LEVEL_MEDIOCRE;
else if (intScore > 34 && intScore < 45)
return PASSWORD_LEVEL_STRONG;
else
return PASSWORD_LEVEL_VERYSTRONG;
}
}
On Jul 20, 12:30 pm, omsrobert <[email protected]> wrote:
> Anyone have a password strength widget for either GWT or GXT? Client
> side or better client w/server side validation would be great.
--
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-web-toolkit?hl=en.