-
Notifications
You must be signed in to change notification settings - Fork 87
Feat/dev ut #316
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Feat/dev ut #316
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,6 +35,9 @@ public class SM3PasswordUtil { | |
| * SM3 哈希计算 | ||
| */ | ||
| public static String sm3Hash(String data, String salt) throws Exception { | ||
| if(data == null || salt == null) { | ||
| throw new IllegalArgumentException("数据和盐值不能为空"); | ||
| } | ||
| MessageDigest md = MessageDigest.getInstance(SM3_ALGORITHM, "BC"); | ||
| String dataWithSalt = data + salt; | ||
| byte[] hash = md.digest(dataWithSalt.getBytes("UTF-8")); | ||
|
|
@@ -54,6 +57,9 @@ public static PasswordResult createPassword(String plainPassword) throws Excepti | |
| * 验证用户密码 | ||
| */ | ||
| public static boolean verifyPassword(String inputPassword, String storedHash, String salt) throws Exception { | ||
| if(inputPassword == null || storedHash == null || salt == null) { | ||
| throw new IllegalArgumentException("输入密码、存储哈希和盐值不能为空"); | ||
| } | ||
|
Comment on lines
+60
to
+62
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🩺 Stability & Availability | 🟠 Major | ⚡ Quick win Don't surface bad-login inputs as uncaught exceptions. Line 60 changes 🤖 Prompt for AI Agents |
||
| String computedHash = sm3Hash(inputPassword, salt); | ||
| return computedHash.equals(storedHash); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Message claims "null or empty" but only null is rejected.
An empty/blank
tokenfalls through to parsing and returnsfalse(covered byvalidateTokenReturnsFalseForEmptyToken). Either align the message with the actual check or also reject blank tokens.🩹 Align message with the check
📝 Committable suggestion
🤖 Prompt for AI Agents