Sfoglia il codice sorgente

修改登录密码判断逻辑

王鸿臣 1 anno fa
parent
commit
76359a0a43

+ 13 - 11
backend/src/main/java/com/jiayue/ssi/config/MyAuthenticationProvider.java

@@ -14,11 +14,11 @@ import org.springframework.security.crypto.password.PasswordEncoder;
 import javax.annotation.Resource;
 
 /**
-* security密码对比
-*
-* @author xsl
-* @since 2023/03/13
-*/
+ * security密码对比
+ *
+ * @author xsl
+ * @since 2023/03/13
+ */
 @Slf4j
 public class MyAuthenticationProvider extends DaoAuthenticationProvider {
 
@@ -36,16 +36,18 @@ public class MyAuthenticationProvider extends DaoAuthenticationProvider {
             String decryptPassword = null;
             //解密登陆密码
             try {
-                decryptPassword= SmUtil.sm3(presentedPassword).toUpperCase();
-            } catch (Exception e) {
-                log.error("用户密码解密错误,无法登录!");
-            }
+                decryptPassword = SmUtil.sm3(presentedPassword).toUpperCase();
+
 //            if (!this.passwordEncoder.matches(decryptPassword, userDetails.getPassword())) {
 //                this.logger.debug("Authentication failed: password does not match stored value");
 //                throw new BadCredentialsException(this.messages.getMessage("AbstractUserDetailsAuthenticationProvider.badCredentials", "Bad credentials"));
 //            }
-            if (!decryptPassword.equals(SM2CryptUtils.decrypt(userDetails.getPassword(), SecretKeyConstants.SERVER_PRIVATE_KEY))) {
-                this.logger.debug("Authentication failed: password does not match stored value");
+                if (!decryptPassword.equals(SM2CryptUtils.decrypt(userDetails.getPassword(), SecretKeyConstants.SERVER_PRIVATE_KEY))) {
+                    this.logger.debug("Authentication failed: password does not match stored value");
+                    throw new BadCredentialsException(this.messages.getMessage("AbstractUserDetailsAuthenticationProvider.badCredentials", "Bad credentials"));
+                }
+            } catch (Exception e) {
+                log.error("用户密码解密错误,无法登录!");
                 throw new BadCredentialsException(this.messages.getMessage("AbstractUserDetailsAuthenticationProvider.badCredentials", "Bad credentials"));
             }
         }