示例#1
0
 @Test
 public void testEncode() {
   assertEquals(PasswordEncoder.PREFIX + "UXdlcnR5", PasswordEncoder.encode("Qwerty"));
   assertEquals(
       PasswordEncoder.PREFIX + "Qwerty",
       PasswordEncoder.encode(PasswordEncoder.PREFIX + "Qwerty"));
 }
示例#2
0
  @Test
  public void testSha1Hash2() {
    final PasswordEncoder pe = new DefaultPasswordEncoder("SHA1");

    final String hash = pe.encode("TEST of the SYSTEM");

    assertEquals("82ae28dfad565dd9882b94498a271caa29025d5f", hash);
  }
示例#3
0
  @Test
  public void testSha1Hash() {
    final PasswordEncoder pe = new DefaultPasswordEncoder("SHA1");

    final String hash = pe.encode("this is a test");

    assertEquals("fa26be19de6bff93f70bc2308434e4a440bbad02", hash);
  }
示例#4
0
 @Test
 public void testInvalidEncodingType() {
   final PasswordEncoder pe = new DefaultPasswordEncoder("scott");
   try {
     pe.encode("test");
     fail("exception expected.");
   } catch (final Exception e) {
     return;
   }
 }
示例#5
0
 @Test
 public void testDisablePwEncoder() {
   System.setProperty("zookeeper.password.encode", "false");
   assertEquals("UXdlcnR5", PasswordEncoder.decode("UXdlcnR5"));
   assertEquals(
       PasswordEncoder.PREFIX + "UXdlcnR5",
       PasswordEncoder.decode(PasswordEncoder.PREFIX + "UXdlcnR5"));
   assertEquals("Qwerty", PasswordEncoder.encode("Qwerty"));
   assertEquals(
       PasswordEncoder.PREFIX + "Qwerty",
       PasswordEncoder.encode(PasswordEncoder.PREFIX + "Qwerty"));
 }
  @Test
  public void testEncryptAndVerify() throws Exception {
    PasswordEncoder encoder = lookup(PasswordEncoder.class, "crypt");

    String crypted = encoder.encodePassword("test", null);

    // System.out.println( "Crypted password: \'" + crypted + "\'" );

    int lastIdx = crypted.lastIndexOf('$');
    int firstIdx = crypted.indexOf('$');

    String salt = crypted.substring(firstIdx + "$1$".length(), lastIdx);

    String check = "{CRYPT}" + MD5Crypt.unixMD5("test", salt);

    // System.out.println( "Check value: \'" + check + "\'" );

    Assert.assertEquals(check, crypted);

    Assert.assertTrue(encoder.isPasswordValid(crypted, "test", null));
  }
 public void addUser(String username, String password) {
   LOG.debug("addUser( " + username + ")");
   String md5Password = PasswordEncoder.convertToMD5String(password);
   dao.createUser(username, md5Password);
 }