You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@shiro.apache.org by fp...@apache.org on 2019/11/21 18:05:39 UTC

[shiro] branch master updated: SHIRO-458 - Refining merge + fixing another location

This is an automated email from the ASF dual-hosted git repository.

fpapon pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shiro.git


The following commit(s) were added to refs/heads/master by this push:
     new 66eed8b  SHIRO-458 - Refining merge + fixing another location
     new 79662c5  Merge pull request #183 from coheigea/SHIRO-458
66eed8b is described below

commit 66eed8b590b3b797d0800cdfbc4522383c235c88
Author: Colm O hEigeartaigh <co...@apache.org>
AuthorDate: Wed Nov 20 10:32:19 2019 +0000

    SHIRO-458 - Refining merge + fixing another location
---
 .../authc/credential/DefaultPasswordService.java    | 21 ++++++---------------
 1 file changed, 6 insertions(+), 15 deletions(-)

diff --git a/core/src/main/java/org/apache/shiro/authc/credential/DefaultPasswordService.java b/core/src/main/java/org/apache/shiro/authc/credential/DefaultPasswordService.java
index 26000e6..c2ec183 100644
--- a/core/src/main/java/org/apache/shiro/authc/credential/DefaultPasswordService.java
+++ b/core/src/main/java/org/apache/shiro/authc/credential/DefaultPasswordService.java
@@ -18,6 +18,8 @@
  */
 package org.apache.shiro.authc.credential;
 
+import java.security.MessageDigest;
+
 import org.apache.shiro.crypto.hash.DefaultHashService;
 import org.apache.shiro.crypto.hash.Hash;
 import org.apache.shiro.crypto.hash.HashRequest;
@@ -99,21 +101,10 @@ public class DefaultPasswordService implements HashingPasswordService {
 
     private boolean constantEquals(String savedHash, String computedHash) {
 
-        int result = 0;
-        boolean equals;
-        byte [] savedHashByteArray = savedHash.getBytes();
-        byte [] computedHashByteArray = computedHash.getBytes();
-
-        if(savedHashByteArray.length != computedHashByteArray.length){
-            return false;
-        } else {
-            for(int index = 0; index < savedHashByteArray.length; index++){
-                result |= savedHashByteArray[index] ^ computedHashByteArray[index];
-            }
-            equals = (result == 0);
-        }
+        byte[] savedHashByteArray = savedHash.getBytes();
+        byte[] computedHashByteArray = computedHash.getBytes();
 
-        return equals;
+        return MessageDigest.isEqual(savedHashByteArray, computedHashByteArray);
     }
 
     protected void checkHashFormatDurability() {
@@ -180,7 +171,7 @@ public class DefaultPasswordService implements HashingPasswordService {
         Hash computed = this.hashService.computeHash(request);
         String formatted = this.hashFormat.format(computed);
 
-        return saved.equals(formatted);
+        return constantEquals(saved, formatted);
     }
 
     protected HashRequest buildHashRequest(ByteSource plaintext, Hash saved) {