import org.apache.shiro.crypto.SecureRandomNumberGenerator;
import org.apache.shiro.crypto.hash.SimpleHash;
import org.junit.Test;

/**
 * Created by Will.Zhang on 2016/12/5 0005 14:49.
 */
public class PasswordTest extends BaseTest{

    @Test
    public void testPasswordServiceWithMyrealm(){
        login("classpath:shiro-passwordService.ini","zhang","123");
    }

    @Test
    public void testPasswordServiceWithJdbcRealm(){
        login("classpath:shiro-jdbc-passwordService.ini","zhang","123");
    }

    @Test
    public void testGeneratePassword(){
        String algorithmName = "md5";
        String username = "liu";
        String password = "123";
        String salt1 = username;
        String salt2 = new SecureRandomNumberGenerator().nextBytes().toHex();
        int hashIteration = 2;

        SimpleHash simpleHash = new SimpleHash(algorithmName, password, salt1 + salt2, hashIteration);
        String encodePassword = simpleHash.toHex();
        System.out.println(salt2);
        System.out.println(encodePassword);
    }

    @Test
    public void testHashedCredentialsMatcherWithMyRealm2(){
        //使用testGeneratePassword生成的散列密码
        login("classpath:shiro-hashedCredentialsMatcher.ini", "liu", "123");
    }
}

@@ -1,28 +1,145 @@
+import org.apache.commons.beanutils.BeanUtilsBean;%0Aimport org.apache.commons.beanutils.converters.AbstractConverter;%0A
 import org.apache.shiro.cryp
@@ -218,16 +218,62 @@
 leHash;%0A
+import org.apache.shiro.realm.jdbc.JdbcRealm;%0A
 import o
@@ -1398,11 +1398,754 @@
 );%0A    %7D
+%0A%0A    @Test%0A    public void testHashedCredentialsMatcherWithJdbcRealm()%7B%0A%0A        BeanUtilsBean.getInstance().getConvertUtils().register(new EnumConverter(), JdbcRealm.SaltStyle.class);%0A        //%E4%BD%BF%E7%94%A8testGeneratePassword%E7%94%9F%E6%88%90%E7%9A%84%E6%95%A3%E5%88%97%E5%AF%86%E7%A0%81%0A        login(%22classpath:shiro-jdbc-hashedCredentialsMatcher.ini%22, %22liu%22, %22123%22);%0A    %7D%0A%0A    private class EnumConverter extends AbstractConverter %7B%0A%0A        protected String convertToString(final Object value) throws Throwable %7B%0A            return ((Enum)value).name();%0A        %7D%0A%0A        protected Object convertToType(Class type, Object value) throws Throwable %7B%0A            return Enum.valueOf(type, value.toString());%0A        %7D%0A%0A        protected Class getDefaultType() %7B%0A            return null;%0A        %7D%0A    %7D
 %0A%7D%0A

update section5