You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Raible, Matt" <Ma...@cable.comcast.com> on 2003/04/05 00:56:57 UTC

Password rules with the Validator?

Does anyone know of any open source packages or techniques for implementing
password rules. For instance, I need to implement the following rules for
password in my application:

Passwords must be made up of at least three (3) of the four (4) following 
classes of characters: Lowercase letters, Uppercase letters, Numbers,
Special 
Characters.

I can probably whip up some JavaScript for this, but I'd need server-side
code to catch if JavaScript is disabled. I'm guessing this is not possible
with regular expressions in the Validator.

Thanks,

Matt



---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


RE: Password rules with the Validator?

Posted by Michael Marrotte <ma...@nicusa.com>.
I've done it before by extending the validator.

validation.xml

    <form name="form">

      <field property="password" depends="password">
        <arg0 key="password"/>
      </field>

    </form>

validator-rules.xml
<validator
      name="password"
      classname="ExtendedStrutsValidator"
      method="validatePassword"
      methodParams="java.lang.Object,
                    org.apache.commons.validator.ValidatorAction,
                    org.apache.commons.validator.Field,
                    org.apache.struts.action.ActionErrors,
                    javax.servlet.http.HttpServletRequest"
      depends="required"
      msg="errors.password">
    </validator>

public class ExtendedStrutsValidator extends StrutsValidator {

  public static boolean validatePassword(Object bean,
  ValidatorAction va, Field field,
  ActionErrors errors,
  HttpServletRequest request) {
    String value = ValidatorUtil.getValueAsString(bean,
field.getProperty());

    if (!GenericValidator.isBlankOrNull(value)) {
      try {
        if (!isValidPassword(value)) {
          errors.add(field.getKey(),
          StrutsValidatorUtil.getActionError(request, va, field));

          return false;
        }
      } catch (Exception e) {
        errors.add(field.getKey(),
        StrutsValidatorUtil.getActionError(request, va, field));
        return false;
      }
    }
    return true;
  }

  private static boolean isValidPassword(String password) {
    boolean isValid = true;

	isValid = /* Passwords must be made up of at least three (3) of the four
(4) following
classes of characters: Lowercase letters, Uppercase letters, Numbers,
Special
Characters.*/
	return isValid;
  }
}

--Michael Marrotte

-----Original Message-----
From: Raible, Matt [mailto:Matt_Raible@cable.comcast.com]
Sent: Friday, April 04, 2003 5:57 PM
To: 'struts-user@jakarta.apache.org'
Subject: Password rules with the Validator?


Does anyone know of any open source packages or techniques for implementing
password rules. For instance, I need to implement the following rules for
password in my application:

Passwords must be made up of at least three (3) of the four (4) following
classes of characters: Lowercase letters, Uppercase letters, Numbers,
Special
Characters.

I can probably whip up some JavaScript for this, but I'd need server-side
code to catch if JavaScript is disabled. I'm guessing this is not possible
with regular expressions in the Validator.

Thanks,

Matt



---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org