#1400 Sync AuthMe's phpBB hash implementation with phpBB3's

- phpBB3 seems to favor using BCrypt $2y$ now
- Keep unsalted MD5 and phpass salted MD5 comparisons for backwards compatibility
This commit is contained in:
ljacqu
2017-11-04 09:58:51 +01:00
parent 80f9ec88b8
commit 80ab41ae5a
2 changed files with 177 additions and 130 deletions
@@ -1,5 +1,12 @@
package fr.xephi.authme.security.crypts;
import com.google.common.collect.ImmutableMap;
import org.junit.Test;
import java.util.Map;
import static org.junit.Assert.fail;
/**
* Test for {@link PhpBB}.
*/
@@ -7,10 +14,46 @@ public class PhpBBTest extends AbstractEncryptionMethodTest {
public PhpBBTest() {
super(new PhpBB(),
"$H$7MaSGQb0xe3Fp/a.Q.Ewpw.UKfCv.t0", // password
"$H$7ESfAVjzqajC7fJFcZKZIhyds41MuW.", // PassWord1
"$H$7G65SXRPbR69jLg.qZTjtqsw36Ciw7.", // &^%te$t?Pw@_
"$H$7Brcg8zO9amr2SHVgz.pFxprDu40v4/"); // âË_3(íù*
"$2a$10$1rnuna3GBduBy1NQuOpnWODqBfl8CZHeULuBThNfAvkOYDRRQR1Zi", // password
"$2a$10$F6LVgXa8.t95H0Fikr6nG.aEMgIQRXlFpzMvAjbO7ag3fny9GGS3i", // PassWord1
"$2a$10$ex57hkfuMLwYsdG8ru/4teh48kHCSv0HPLPjhhHsEB3NqXiOi7RQS", // &^%te$t?Pw@_
"$2a$10$2B/HAJ3MeoxGQgqLM6GDlOBqd.2uzLPi1VznXlrXcayLixSaRIWqC"); // âË_3(íù*
}
@Test
public void shouldMatchPhpassSaltedMd5Hashes() {
// given
Map<String, String> givenHashes = ImmutableMap.of(
"password", "$H$7MaSGQb0xe3Fp/a.Q.Ewpw.UKfCv.t0",
"PassWord1", "$H$7ESfAVjzqajC7fJFcZKZIhyds41MuW.",
"&^%te$t?Pw@_", "$H$7G65SXRPbR69jLg.qZTjtqsw36Ciw7.",
"âË_3(íù*", "$H$7Brcg8zO9amr2SHVgz.pFxprDu40v4/");
PhpBB phpBB = new PhpBB();
// when / then
for (Map.Entry<String, String> hashEntry : givenHashes.entrySet()) {
if (!phpBB.comparePassword(hashEntry.getKey(), new HashedPassword(hashEntry.getValue()), null)) {
fail("Hash comparison for '" + hashEntry.getKey() + "' failed");
}
}
}
@Test
public void shouldMatchUnsaltedMd5Hashes() {
// given
Map<String, String> givenHashes = ImmutableMap.of(
"password", "5f4dcc3b5aa765d61d8327deb882cf99",
"PassWord1", "f2126d405f46ed603ff5b2950f062c96",
"&^%te$t?Pw@_", "0833dcd2bc741f90c46bbac5498fd08f",
"âË_3(íù*", "e7412bf1a9d312dc2901c3101a097abe");
PhpBB phpBB = new PhpBB();
// when / then
for (Map.Entry<String, String> hashEntry : givenHashes.entrySet()) {
if (!phpBB.comparePassword(hashEntry.getKey(), new HashedPassword(hashEntry.getValue()), null)) {
fail("Hash comparison for '" + hashEntry.getKey() + "' failed");
}
}
}
}