prevent timing attacks by using a time-constant comparison algorithm

This commit is contained in:
Athou
2014-08-13 17:08:42 +02:00
parent fa212e0911
commit 62a8e8c119

View File

@@ -1,10 +1,10 @@
package com.commafeed.backend.service;
import java.io.Serializable;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.security.spec.KeySpec;
import java.util.Arrays;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
@@ -30,7 +30,7 @@ public class PasswordEncryptionService implements Serializable {
// Authentication succeeds if encrypted password that the user entered
// is equal to the stored hash
return Arrays.equals(encryptedPassword, encryptedAttemptedPassword);
return MessageDigest.isEqual(encryptedPassword, encryptedAttemptedPassword);
}
public byte[] getEncryptedPassword(String password, byte[] salt) {