修复PasswdStrength.checkindexOf逻辑问题(pr#4114@Github)。

This commit is contained in:
Looly 2025-10-24 16:00:20 +08:00
parent b136d81720
commit 4162c519b7
3 changed files with 33 additions and 31 deletions

View File

@ -1,7 +1,7 @@
# 🚀Changelog
-------------------------------------------------------------------------------------------------------------
# 5.8.42(2025-10-23)
# 5.8.42(2025-10-24)
### 🐣新特性
* 【core 】 `ListUtil`增加`zip`方法pr#4052@Github
@ -13,6 +13,7 @@
* 【jwt 】 修复verify方法在定义alg为`none`时验证失效问题issue#4105@Github
* 【extra 】 修复`JschSessionPool.remove`逻辑错误问题。
* 【db 】 修复`Dialect.psForCount`未传入Wrapper导致大小写问题issue#ID39G9@Gitee)。
* 【core 】 修复`PasswdStrength.check`indexOf逻辑问题pr#4114@Github)。
-------------------------------------------------------------------------------------------------------------
# 5.8.41(2025-10-12)

View File

@ -15,7 +15,7 @@ public class PasswdStrength {
* 密码等级枚举
*/
public enum PASSWD_LEVEL {
EASY, MEDIUM, STRONG, VERY_STRONG, EXTREMELY_STRONG
EASY, MIDIUM, STRONG, VERY_STRONG, EXTREMELY_STRONG
}
/**
@ -176,7 +176,7 @@ public class PasswdStrength {
// 检测密码是否为简单密码字典中的弱密码或包含字典弱密码片段
for (String s : DICTIONARY) {
if (passwd.equals(s) || passwd.contains(s)) {
if (passwd.equals(s) || s.contains(passwd)) {
level--;
break;
}
@ -220,7 +220,7 @@ public class PasswdStrength {
case 4:
case 5:
case 6:
return PASSWD_LEVEL.MEDIUM;
return PASSWD_LEVEL.MIDIUM;
case 7:
case 8:
case 9:

View File

@ -1,8 +1,9 @@
package cn.hutool.core.text;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class PasswdStrengthTest {
@Test
public void strengthTest(){
@ -28,7 +29,7 @@ public class PasswdStrengthTest {
public void dictionaryWeakPasswordTest() {
// 测试包含简单密码字典中的弱密码
assertEquals(0, PasswdStrength.check("password"));
assertEquals(2, PasswdStrength.check("password2"));
assertEquals(3, PasswdStrength.check("password2"));
}
@Test