密码强度定义描述说明

This commit is contained in:
shibanglin 2023-03-07 11:34:14 +08:00
parent 5a71ba7c62
commit 9175a3b09c
4 changed files with 88 additions and 16 deletions

View File

@ -1,19 +1,19 @@
/*
* Copyright [2020] [MaxKey of copyright http://www.maxkey.top]
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.maxkey.entity;
@ -27,6 +27,10 @@ import javax.validation.constraints.NotNull;
import org.apache.mybatis.jpa.persistence.JpaBaseEntity;
import org.maxkey.constants.ConstsServiceMessage;
import org.maxkey.exception.PasswordPolicyException;
import org.maxkey.web.WebContext;
import java.util.ArrayList;
import java.util.List;
/**
* @author Crystal.Sea
@ -107,24 +111,88 @@ public class PasswordPolicy extends JpaBaseEntity implements java.io.Serializabl
*/
@Column
private int history;
@Column
private int dictionary;
@Column
private int alphabetical;
@Column
private int numerical;
@Column
private int qwerty;
@Column
private int occurances;
private int randomPasswordLength;
List<String> policMessageList;
public void buildMessage(){
if(policMessageList==null){
policMessageList = new ArrayList<>();
}
String msg;
if (minLength != 0) {
// msg = "新密码长度为"+minLength+"-"+maxLength+"";
msg = WebContext.getI18nValue("PasswordPolicy.TOO_SHORT",
new Object[]{minLength});
policMessageList.add(msg);
}
if (maxLength != 0) {
// msg = "新密码长度为"+minLength+"-"+maxLength+"";
msg = WebContext.getI18nValue("PasswordPolicy.TOO_LONG",
new Object[]{maxLength});
policMessageList.add(msg);
}
if (lowerCase > 0) {
//msg = "新密码至少需要包含"+lowerCase+"位【a-z】小写字母";
msg = WebContext.getI18nValue("PasswordPolicy.INSUFFICIENT_LOWERCASE",
new Object[]{lowerCase});
policMessageList.add(msg);
}
if (upperCase > 0) {
//msg = "新密码至少需要包含"+upperCase+"位【A-Z】大写字母";
msg = WebContext.getI18nValue("PasswordPolicy.INSUFFICIENT_UPPERCASE",
new Object[]{upperCase});
policMessageList.add(msg);
}
if (digits > 0) {
//msg = "新密码至少需要包含"+digits+"位【0-9】阿拉伯数字";
msg = WebContext.getI18nValue("PasswordPolicy.INSUFFICIENT_DIGIT",
new Object[]{digits});
policMessageList.add(msg);
}
if (specialChar > 0) {
//msg = "新密码至少需要包含"+specialChar+"位特殊字符";
msg = WebContext.getI18nValue("PasswordPolicy.INSUFFICIENT_SPECIAL",
new Object[]{specialChar});
policMessageList.add(msg);
}
if (expiration > 0) {
//msg = "新密码有效期为"+expiration+"";
msg = WebContext.getI18nValue("PasswordPolicy.INSUFFICIENT_EXPIRES_DAY",
new Object[]{expiration});
policMessageList.add(msg);
}
}
public List<String> getPolicMessageList() {
return policMessageList;
}
public void setPolicMessageList(List<String> policMessageList) {
this.policMessageList = policMessageList;
}
/**
* @return the minLength
*/
@ -331,7 +399,7 @@ public class PasswordPolicy extends JpaBaseEntity implements java.io.Serializabl
public void setOccurances(int occurances) {
this.occurances = occurances;
}
public int getRandomPasswordLength() {
return randomPasswordLength;
}
@ -428,5 +496,5 @@ public class PasswordPolicy extends JpaBaseEntity implements java.io.Serializabl
return builder.toString();
}
}

View File

@ -25,12 +25,14 @@ PasswordPolicy.INSUFFICIENT_CHARACTERISTICS=\u5BC6\u7801\u5339\u914D {0} of{2}\u
PasswordPolicy.INSUFFICIENT_COMPLEXITY=\u5BC6\u7801\u9047\u5230{1}\u590D\u6742\u89C4\u5219, \u4F46{2}\u5FC5\u987B.
PasswordPolicy.INSUFFICIENT_COMPLEXITY_RULES=\u6CA1\u6709\u914D\u7F6E\u5BC6\u7801\u957F\u5EA6\u89C4\u5219 {0}.
PasswordPolicy.SOURCE_VIOLATION=\u5BC6\u7801\u4E0D\u80FD\u5305\u542B{0}\u5BC6\u7801.
PasswordPolicy.TOO_LONG=\u5BC6\u7801\u6700\u591A{1}\u4F4D\u5B57\u7B26.
PasswordPolicy.TOO_LONG=\u5BC6\u7801\u6700\u591A{0}\u4F4D\u5B57\u7B26.
PasswordPolicy.TOO_SHORT=\u5BC6\u7801\u81F3\u5C11{0}\u4F4D\u5B57\u7B26.
PasswordPolicy.TOO_MANY_OCCURRENCES=\u5BC6\u7801\u5305\u542B{0}\u51FA\u73B0{1}, \u6700\u591A{2} \u6B21.
PasswordPolicy.OLD_PASSWORD_NOT_MATCH=\u539F\u5BC6\u7801\u4E0D\u5339\u914D.
PasswordPolicy.CONFIRMPASSWORD_NOT_MATCH=\u65B0\u5BC6\u7801\u4E0E\u786E\u8BA4\u5BC6\u7801\u4E0D\u4E00\u81F4.
PasswordPolicy.OLD_PASSWORD_MATCH=\u65B0\u5BC6\u7801\u4E0D\u80FD\u4E0E\u65E7\u5BC6\u7801\u4E00\u81F4.
PasswordPolicy.INSUFFICIENT_EXPIRES_DAY=\u5bc6\u7801\u6709\u6548\u671f\u4e3a{0}\u5929.
#\u7528\u6237\u767B\u5F55\u9519\u8BEF\u63D0\u9192
login.error.attempts=\u767B\u5F55\u9519\u8BEF\u8FBE\u6700\u5927\u9650\u5236{0}\u6B21,\u8BF7{1}\u5206\u949F\u540E\u91CD\u8BD5.

View File

@ -25,13 +25,13 @@ PasswordPolicy.INSUFFICIENT_CHARACTERISTICS=Password matches {0} of {2} characte
PasswordPolicy.INSUFFICIENT_COMPLEXITY=Password meets {1} complexity rules, but {2} are required.
PasswordPolicy.INSUFFICIENT_COMPLEXITY_RULES=No rules have been configured for a password of length {0}.
PasswordPolicy.SOURCE_VIOLATION=Password cannot be the same as your {0} password.
PasswordPolicy.TOO_LONG=Password must be no more than {1} characters in length.
PasswordPolicy.TOO_LONG=Password must be no more than {0} characters in length.
PasswordPolicy.TOO_SHORT=Password must be {0} or more characters in length .
PasswordPolicy.TOO_MANY_OCCURRENCES=Password contains {1} occurrences of the character {0}, but at most {2} are allowed.
PasswordPolicy.OLD_PASSWORD_NOT_MATCH=old password not match.
PasswordPolicy.CONFIRMPASSWORD_NOT_MATCH=new password not match confirm password.
PasswordPolicy.OLD_PASSWORD_MATCH=new password match old password.
PasswordPolicy.INSUFFICIENT_EXPIRES_DAY=The password is valid for {0} days
#for user login
login.error.attempts=login attempts the maximum {0} times, please login {1} minutes later.
login.error.locked=The user is locked.

View File

@ -25,12 +25,14 @@ PasswordPolicy.INSUFFICIENT_CHARACTERISTICS=\u5BC6\u7801\u5339\u914D {0} of{2}\u
PasswordPolicy.INSUFFICIENT_COMPLEXITY=\u5BC6\u7801\u9047\u5230{1}\u590D\u6742\u89C4\u5219, \u4F46{2}\u5FC5\u987B.
PasswordPolicy.INSUFFICIENT_COMPLEXITY_RULES=\u6CA1\u6709\u914D\u7F6E\u5BC6\u7801\u957F\u5EA6\u89C4\u5219 {0}.
PasswordPolicy.SOURCE_VIOLATION=\u5BC6\u7801\u4E0D\u80FD\u5305\u542B{0}\u5BC6\u7801.
PasswordPolicy.TOO_LONG=\u5BC6\u7801\u6700\u591A{1}\u4F4D\u5B57\u7B26.
PasswordPolicy.TOO_LONG=\u5BC6\u7801\u6700\u591A{0}\u4F4D\u5B57\u7B26.
PasswordPolicy.TOO_SHORT=\u5BC6\u7801\u81F3\u5C11{0}\u4F4D\u5B57\u7B26.
PasswordPolicy.TOO_MANY_OCCURRENCES=\u5BC6\u7801\u5305\u542B{0}\u51FA\u73B0{1}, \u6700\u591A{2} \u6B21.
PasswordPolicy.OLD_PASSWORD_NOT_MATCH=\u539F\u5BC6\u7801\u4E0D\u5339\u914D.
PasswordPolicy.CONFIRMPASSWORD_NOT_MATCH=\u65B0\u5BC6\u7801\u4E0E\u786E\u8BA4\u5BC6\u7801\u4E0D\u4E00\u81F4.
PasswordPolicy.OLD_PASSWORD_MATCH=\u65B0\u5BC6\u7801\u4E0D\u80FD\u4E0E\u65E7\u5BC6\u7801\u4E00\u81F4.
PasswordPolicy.INSUFFICIENT_EXPIRES_DAY=\u5bc6\u7801\u6709\u6548\u671f\u4e3a{0}\u5929.
#\u7528\u6237\u767B\u5F55\u9519\u8BEF\u63D0\u9192
login.error.attempts=\u767B\u5F55\u9519\u8BEF\u8FBE\u6700\u5927\u9650\u5236{0}\u6B21,\u8BF7{1}\u5206\u949F\u540E\u91CD\u8BD5.