com.yishuifengxiao.common.tool.validate.PasswordValidator Maven / Gradle / Ivy
package com.yishuifengxiao.common.tool.validate;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import org.springframework.util.StringUtils;
/**
* 自定义密码校验器
*
* @author yishui
* @date 2018年7月27日
* @Version 0.0.1
*/
public class PasswordValidator implements ConstraintValidator {
private String[] forbiddenWords = { "admin" };
@Override
public void initialize(Password constraintAnnotation) {
// 初始化,得到注解数据
}
@Override
public boolean isValid(String value, ConstraintValidatorContext context) {
if (StringUtils.isEmpty(value)) {
return true;
}
for (String word : forbiddenWords) {
if (value.contains(word)) {
// 验证失败
return false;
}
}
return true;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy