← Back


PasswordComponent for input, generation and evaluation of passwords



This component can be used for setting/confirming passwords manually or for generating random passwords. It also evaluates password strength real-time. The component consists of multiple GWT widgets. A textfield for password input, a textfield for password confirmation (if the component is in password mode), two radio buttons two switch between password mode and text mode and an image for password generation. The strength indicators are images too. All images are base64 encoded but URL's can also be used. The component also has all necessary text labels for the input fields. All text and images can be substituted with help of the public setters of this component. The static methods defined by the Password-class can be used for validating user input on both client-side and server-side. A password is considered strong if it is at least 8 characters long and has at least one character from each of these four groups: -lowercase character -uppercase character -number -special character

Key features: *2 modes where password mode with password confirmation and plain text mode without confirmation. *All text and images can be substituted with server-side setters. *Password generator that generates 8 character long passwords which have at least one lowercase character, one uppercase character one number and one special character. *Real-time 4-scale client-side password strength evaluation. *Characters O,0,I,1 and some other characters are excluded from password generation. *Same password generation/evaluation can be used server-side because it is written in Java.

Sample code

public static int strength(final String password) {

        // Contains at least one upper case letter
        final int upperCase = matches(password, "^.*[A-Z].*$");

        // Contains at least one lower case letter
        final int lowerCase = matches(password, "^.*[a-z].*$");

        // Contains at least one number
        final int numbers = matches(password, "^.*[0-9].*$");

        // Contains at least one special character
        final int specialCharacters = matches(password,
        final int sum = upperCase + lowerCase + numbers + specialCharacters;
        if (sum <= 1 || password.length() < 6
                || password.toLowerCase().equals("password")
                || password.toLowerCase().equals("salasana")) {
            return 0;
        } else if (sum == 2 || (sum == 3 && password.length() < 8)) {
            return 1;
        } else if (sum == 3 || (sum == 4 && password.length() < 8)) {
            return 2;
        } else {
            return 3;



(Loading compatibility data...)

Was this helpful? Need more help?
Leave a comment or a question below. You can also join the chat on Discord or ask questions on StackOverflow.


Apache License 2.0


Vaadin 7.0
Google Chrome