### Question:
PasswordHashCreatorBCrypt extends AbstractPasswordHashCreator { @Nonnull public String createPasswordHash (@Nonnull final IPasswordSalt aSalt, @Nonnull final String sPlainTextPassword) { ValueEnforcer.notNull (aSalt, "Salt"); ValueEnforcer.isInstanceOf (aSalt, PasswordSaltBCrypt.class, "Salt"); ValueEnforcer.notNull (sPlainTextPassword, "PlainTextPassword"); return BCrypt.hashpw (sPlainTextPassword, aSalt.getSaltString ()); } PasswordHashCreatorBCrypt(); boolean requiresSalt(); @Nonnull String createPasswordHash(@Nonnull final IPasswordSalt aSalt, @Nonnull final String sPlainTextPassword); static final String ALGORITHM; }### Answer:
@Test public void testBasicSameSalt () { final IPasswordSalt aSalt = new PasswordSaltBCrypt (); final String sPlainTextPassword = "123456"; final PasswordHashCreatorBCrypt a = new PasswordHashCreatorBCrypt (); final String sPW1 = a.createPasswordHash (aSalt, sPlainTextPassword); final String sPW2 = a.createPasswordHash (aSalt, sPlainTextPassword); assertEquals (sPW1, sPW2); }
@Test public void testBasicDifferentSalt () { final String sPlainTextPassword = "123456"; final PasswordHashCreatorBCrypt a = new PasswordHashCreatorBCrypt (); final String sPW1 = a.createPasswordHash (new PasswordSaltBCrypt (), sPlainTextPassword); final String sPW2 = a.createPasswordHash (new PasswordSaltBCrypt (), sPlainTextPassword); assertFalse (sPW1.equals (sPW2)); }
@Test public void testCreateMultipleHashes () { final IPasswordSalt aSalt = new PasswordSaltBCrypt (); final String sPlainTextPassword = "123456"; final PasswordHashCreatorBCrypt a = new PasswordHashCreatorBCrypt (); for (int i = 0; i < 20; ++i) a.createPasswordHash (aSalt, sPlainTextPassword); }