All Downloads are FREE. Search and download functionalities are using the official Maven repository.

edu.vt.middleware.password.RepeatCharacterRegexRule Maven / Gradle / Ivy

The newest version!
/*
  $Id: RepeatCharacterRegexRule.java 2704 2013-04-24 21:30:32Z dfisher $

  Copyright (C) 2003-2013 Virginia Tech.
  All rights reserved.

  SEE LICENSE FOR MORE INFORMATION

  Author:  Middleware Services
  Email:   [email protected]
  Version: $Revision: 2704 $
  Updated: $Date: 2013-04-24 17:30:32 -0400 (Wed, 24 Apr 2013) $
*/
package edu.vt.middleware.password;

/**
 * Rule for determining if a password contains a duplicate ASCII keyboard
 * sequence. See {@link java.util.regex.Pattern} /p{ASCII}. The default sequence
 * length is 5 characters.
 *
 * 
    *
  • Sequences are of the form: 'bbbbb' or '#####'
  • *
* * @author Middleware Services * @version $Revision: 2704 $ $Date: 2013-04-24 17:30:32 -0400 (Wed, 24 Apr 2013) $ */ public class RepeatCharacterRegexRule extends RegexRule { /** Default length of sequence, value is {@value}. */ public static final int DEFAULT_SEQUENCE_LENGTH = 5; /** Minimum length of sequence, value is {@value}. */ public static final int MINIMUM_SEQUENCE_LENGTH = 3; /** Regular expression used by this rule, value is {@value}. */ private static final String REPEAT_CHAR_REGEX = "([^\\x00-\\x1F])\\1{%d}"; /** * Creates a new repeat character regex rule with the default sequence length. */ public RepeatCharacterRegexRule() { this(DEFAULT_SEQUENCE_LENGTH); } /** * Creates a new repeat character regex rule. * * @param sl sequence length */ public RepeatCharacterRegexRule(final int sl) { super(String.format(REPEAT_CHAR_REGEX, sl - 1)); if (sl < MINIMUM_SEQUENCE_LENGTH) { throw new IllegalArgumentException( String.format( "sequence length must be >= %s", MINIMUM_SEQUENCE_LENGTH)); } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy