Exemplo n.º 1
0
 @Test
 public void testHash() {
   String password = "******";
   String hashed;
   hashed = PasswordHelper.hashPassword(password, null);
   assertEquals(password, hashed);
   assertTrue(PasswordHelper.verifyPassword(password, hashed));
   hashed = PasswordHelper.hashPassword(password, PasswordHelper.SSHA);
   assertTrue(hashed.startsWith("{SSHA}"));
   assertTrue(PasswordHelper.verifyPassword(password, hashed));
   hashed = PasswordHelper.hashPassword(password, PasswordHelper.SMD5);
   assertTrue(hashed.startsWith("{SMD5}"));
   assertTrue(PasswordHelper.verifyPassword(password, hashed));
 }
Exemplo n.º 2
0
 @Test
 public void testVerify() {
   assertTrue(PasswordHelper.verifyPassword("abcd", "abcd"));
   assertTrue(
       PasswordHelper.verifyPassword("abcd", "{SSHA}WPvqVeSt0Mr2llICYmAX9+pjtPH271eznDHvrw=="));
   assertTrue(PasswordHelper.verifyPassword("abcd", "{SMD5}/wZ7JQUARlCBq4JFHI57AfbvV7OcMe+v"));
   assertFalse(PasswordHelper.verifyPassword("1234", "abcd"));
   assertFalse(
       PasswordHelper.verifyPassword("1234", "{SSHA}WPvqVeSt0Mr2llICYmAX9+pjtPH271eznDHvrw=="));
   assertFalse(PasswordHelper.verifyPassword("1234", "{SMD5}/wZ7JQUARlCBq4JFHI57AfbvV7OcMe+v"));
   assertFalse(PasswordHelper.verifyPassword(" abcd", "abcd"));
   assertFalse(PasswordHelper.verifyPassword("abcd", "{SSHA}WPvqVeS"));
   assertFalse(PasswordHelper.verifyPassword("abcd", "{SSHA}/wZ7JQUAR"));
   assertFalse(PasswordHelper.verifyPassword("abcd", "{SSHA}WXYZ"));
   assertFalse(
       PasswordHelper.verifyPassword(
           "abcd", "{SSHA}WPvqVeSt0Mr2llICYmAX9+pjtPH271eznDHvrwfghijkl"));
   assertFalse(PasswordHelper.verifyPassword("abcd", "{SSHA}/wZ7JQUARlC*"));
 }