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

io.github.nichetoolkit.rest.worker.PasswordWorker Maven / Gradle / Ivy

The newest version!
package io.github.nichetoolkit.rest.worker;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * PasswordWorker
 * 

The password worker class.

* @author Cyan ([email protected]) * @since Jdk1.8 */ public class PasswordWorker { /** * LOWER_REGEX * {@link java.lang.String}

The constant LOWER_REGEX field.

* @see java.lang.String */ private static final String LOWER_REGEX = "[a-z]"; /** * UPPER_REGEX * {@link java.lang.String}

The constant UPPER_REGEX field.

* @see java.lang.String */ private static final String UPPER_REGEX = "[A-Z]"; /** * NUMBER_REGEX * {@link java.lang.String}

The constant NUMBER_REGEX field.

* @see java.lang.String */ private static final String NUMBER_REGEX = "[0-9]"; /** * password * {@link java.lang.String}

The password field.

* @see java.lang.String */ private final String password; /** * length * {@link java.lang.Integer}

The length field.

* @see java.lang.Integer */ private final Integer length; /** * upperSize * {@link java.lang.Integer}

The upperSize field.

* @see java.lang.Integer */ private Integer upperSize; /** * lowerSize * {@link java.lang.Integer}

The lowerSize field.

* @see java.lang.Integer */ private Integer lowerSize; /** * numSize * {@link java.lang.Integer}

The numSize field.

* @see java.lang.Integer */ private Integer numSize; /** * charSize * {@link java.lang.Integer}

The charSize field.

* @see java.lang.Integer */ private Integer charSize; /** * PasswordWorker *

Instantiates a new password worker.

* @param password {@link java.lang.String}

The password parameter is String type.

* @see java.lang.String */ public PasswordWorker(String password){ this.password = password.replaceAll("\\s", ""); this.length = password.length(); } /** * lengthQuest *

The length quest method.

* @return boolean

The length quest return object is boolean type.

*/ public boolean lengthQuest() { return lengthQuest(8,16); } /** * lengthQuest *

The length quest method.

* @param min int

The min parameter is int type.

* @param max int

The max parameter is int type.

* @return boolean

The length quest return object is boolean type.

*/ public boolean lengthQuest(int min, int max) { /* 密码长度 8-16位 */ return this.length >= min && this.length <= max; } /** * contentQuest *

The content quest method.

* @return boolean

The content quest return object is boolean type.

*/ public boolean contentQuest() { return (getUpperSize() + getLowerSize()) > 0 && getNumSize() > 0; } /** * getUpperSize *

The get upper size getter method.

* @return {@link java.lang.Integer}

The get upper size return object is Integer type.

* @see java.lang.Integer */ public Integer getUpperSize() { if (this.upperSize == null) { this.upperSize = upperMatch(this.password); } return this.upperSize; } /** * getLowerSize *

The get lower size getter method.

* @return {@link java.lang.Integer}

The get lower size return object is Integer type.

* @see java.lang.Integer */ public Integer getLowerSize() { if (this.lowerSize == null) { this.lowerSize = lowerMatch(this.password); } return this.lowerSize; } /** * getNumSize *

The get num size getter method.

* @return {@link java.lang.Integer}

The get num size return object is Integer type.

* @see java.lang.Integer */ public Integer getNumSize() { if (this.numSize == null) { this.numSize = numberMatch(this.password); } return this.numSize; } /** * getCharSize *

The get char size getter method.

* @return int

The get char size return object is int type.

*/ public int getCharSize() { if (this.charSize == null) { this.charSize = this.length - this.getUpperSize() -this.getLowerSize() - this.getNumSize(); } return this.charSize; } /** * upperMatch *

The upper match method.

* @param target {@link java.lang.String}

The target parameter is String type.

* @return {@link java.lang.Integer}

The upper match return object is Integer type.

* @see java.lang.String * @see java.lang.Integer */ public Integer upperMatch(String target) { return match(UPPER_REGEX,target); } /** * lowerMatch *

The lower match method.

* @param target {@link java.lang.String}

The target parameter is String type.

* @return {@link java.lang.Integer}

The lower match return object is Integer type.

* @see java.lang.String * @see java.lang.Integer */ public Integer lowerMatch(String target) { return match(LOWER_REGEX,target); } /** * numberMatch *

The number match method.

* @param target {@link java.lang.String}

The target parameter is String type.

* @return {@link java.lang.Integer}

The number match return object is Integer type.

* @see java.lang.String * @see java.lang.Integer */ public Integer numberMatch(String target) { return match(NUMBER_REGEX,target); } /** * match *

The match method.

* @param regex {@link java.lang.String}

The regex parameter is String type.

* @param target {@link java.lang.String}

The target parameter is String type.

* @return {@link java.lang.Integer}

The match return object is Integer type.

* @see java.lang.String * @see java.lang.Integer */ private Integer match(String regex,String target) { Pattern pattern = Pattern.compile(regex); Matcher matcher = pattern.matcher(target); int length = 0; while (matcher.find()) { length++; } return length; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy