Browse Source

海南陵水双密码校验

linzhiwei 2 years ago
parent
commit
c745846448

+ 5 - 1
tofly-auth/pom.xml

@@ -41,7 +41,11 @@
             <artifactId>common-log</artifactId>
             <version>1.0.3</version>
         </dependency>
-
+        <dependency>
+            <groupId>cn.hutool</groupId>
+            <artifactId>hutool-all</artifactId>
+            <version>5.5.7</version>
+        </dependency>
 
 
         <!--<dependency>-->

+ 11 - 0
tofly-auth/src/main/java/com/tofly/auth/oauth/ToflyAuthenticationProvider.java

@@ -1,5 +1,6 @@
 package com.tofly.auth.oauth;
 
+import cn.hutool.crypto.SecureUtil;
 import com.tofly.auth.util.RSAUtils;
 import com.tofly.common.core.constant.CommonConstants;
 import com.tofly.common.core.constant.SecurityConstants;
@@ -28,6 +29,7 @@ import org.springframework.web.context.request.RequestContextHolder;
 import org.springframework.web.context.request.ServletRequestAttributes;
 
 import javax.servlet.http.HttpServletRequest;
+import java.security.Security;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.Map;
@@ -89,7 +91,16 @@ public class ToflyAuthenticationProvider implements AuthenticationProvider {
 
         log.info("用{}加密后的密码为:{}", SecurityConstants.BCRYPT+password,bCryptPasswordEncoder.encode(SecurityConstants.BCRYPT+password));
         boolean flag = bCryptPasswordEncoder.matches(SecurityConstants.BCRYPT+password, userDetails.getPassword());
+        if(!flag){
+            String sha1 = SecureUtil.sha1(password);
+            log.info("sha1加密:{}",sha1);
+            boolean matches = bCryptPasswordEncoder.matches(SecurityConstants.BCRYPT + sha1, userDetails.getPassword());
+            if(matches){
+                password = sha1;
+                flag = true;
+            }
 
+        }
         //return new UsernamePasswordAuthenticationToken(userDetails,password,userDetails.getAuthorities());
 
         if(StringUtil.isEmpty(password) && !flag){

+ 19 - 0
tofly-auth/src/main/java/com/tofly/auth/util/RSAUtils.java

@@ -1,6 +1,8 @@
 package com.tofly.auth.util;
 
+import com.tofly.common.core.constant.SecurityConstants;
 import org.apache.commons.codec.binary.Base64;
+import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
 import sun.misc.BASE64Decoder;
 
 import javax.crypto.Cipher;
@@ -116,5 +118,22 @@ public class RSAUtils {
         return privateKey;
     }
 
+    public static void main(String[] args) {
+        try {
+//            BCryptPasswordEncoder bCryptPasswordEncoder = new BCryptPasswordEncoder();
+//            String encode = bCryptPasswordEncoder.encode(SecurityConstants.BCRYPT + "000000sS");
+//            System.out.println(encode);
+            String s = priKeyDecryption("q+gfL141i0pfSIZ8vdBY+XqxoeJuf1wJqN8onqpATXTA8HoPervExNaHBaItfkaZ2Kyu81gwJeOtsspCphGgz40D0r7KosBoF6VUBG6cgxDVZ1eaioQfWcyx3k5amgwFMDNifVyo/L9N0KIsOWy2L9f1nvPfsMxT5YCjmyKP4+E=");
+            String s1 = pubKeyEncryption("000000Ll");
+            System.out.println(pubKey);
+            System.out.println(priKey);
+            System.out.println(s);
+            System.out.println(s1);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+    }
+
 }