Password quality meter in GWT

A simple password quality meter is part of the gwt-aux project.
It has a very simple API and implementation, but it is very easy to use as well:

// Minimum password length is 6

final int passwordMinimumLength = 6;

// Create password field

final PasswordTextField passwordField = new PasswordTextField();
passwordField.addValidator(new MinLengthValidator(passwordMinimumLength));
addAndReplaceElement(passwordField, "passwordField");

// Create validation result panel

ValidationResultPanel passwordValidationResultPanel = new ValidationResultPanel(passwordField);
addAndReplaceElement(passwordValidationResultPanel, "passwordValidationResultPanel");

// Create password quality meter

final PasswordQualityMeter passwordQualityMeter = new PasswordQualityMeter(passwordMinimumLength);
addAndReplaceElement(passwordQualityMeter, "passwordQualityMeter");

// Validate field and update password quality meter on every key press

passwordField.addKeyUpHandler(new KeyUpHandler()
 public void onKeyUp(KeyUpEvent event)


No comments:

Post a Comment