From 07e7a8815b4b34233bc25f93b37b92dbe93cbe1e Mon Sep 17 00:00:00 2001 From: ljacqu Date: Mon, 18 Jan 2016 14:19:04 +0100 Subject: [PATCH] Fix #391 Wordpress algorithm fails sometimes --- .../xephi/authme/security/crypts/WORDPRESS.java | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/main/java/fr/xephi/authme/security/crypts/WORDPRESS.java b/src/main/java/fr/xephi/authme/security/crypts/WORDPRESS.java index 8ecb41465..f331d1fc6 100644 --- a/src/main/java/fr/xephi/authme/security/crypts/WORDPRESS.java +++ b/src/main/java/fr/xephi/authme/security/crypts/WORDPRESS.java @@ -1,5 +1,7 @@ package fr.xephi.authme.security.crypts; +import fr.xephi.authme.security.HashUtils; +import fr.xephi.authme.security.MessageDigestAlgorithm; import fr.xephi.authme.security.crypts.description.HasSalt; import fr.xephi.authme.security.crypts.description.Recommendation; import fr.xephi.authme.security.crypts.description.SaltType; @@ -7,12 +9,10 @@ import fr.xephi.authme.security.crypts.description.Usage; import java.io.UnsupportedEncodingException; import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; import java.security.SecureRandom; import java.util.Arrays; -// TODO #391: Wordpress algorithm fails sometimes. Fix it and change the Recommendation to "ACCEPTABLE" if appropriate -@Recommendation(Usage.DO_NOT_USE) +@Recommendation(Usage.ACCEPTABLE) @HasSalt(value = SaltType.TEXT, length = 9) // Note ljacqu 20151228: Wordpress is actually a salted algorithm but salt generation is handled internally // and isn't exposed to the outside, so we treat it as an unsalted implementation @@ -30,6 +30,7 @@ public class WORDPRESS extends UnsaltedMethod { byte[] t = new byte[count]; System.arraycopy(src, 0, t, 0, src.length); Arrays.fill(t, src.length, count - 1, (byte) 0); + src = t; } do { @@ -73,13 +74,7 @@ public class WORDPRESS extends UnsaltedMethod { if (salt.length() != 8) { return output; } - MessageDigest md; - try { - md = MessageDigest.getInstance("MD5"); - } catch (NoSuchAlgorithmException e) { - e.printStackTrace(); - return output; - } + MessageDigest md = HashUtils.getDigest(MessageDigestAlgorithm.MD5); byte[] pass = stringToUtf8(password); byte[] hash = md.digest(stringToUtf8(salt + password)); do {