当前位置: 首页>>代码示例>>Java>>正文


Java SimpleHash类代码示例

本文整理汇总了Java中org.apache.shiro.crypto.hash.SimpleHash的典型用法代码示例。如果您正苦于以下问题:Java SimpleHash类的具体用法?Java SimpleHash怎么用?Java SimpleHash使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


SimpleHash类属于org.apache.shiro.crypto.hash包,在下文中一共展示了SimpleHash类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setupModule

import org.apache.shiro.crypto.hash.SimpleHash; //导入依赖的package包/类
@Override
        public void setupModule(SetupContext context) {
            context.setMixInAnnotations(Object.class, DisableGetters.class);
            context.setMixInAnnotations(Collection.class, DisableTypeInfo.class);
            context.setMixInAnnotations(Map.class, DisableTypeInfo.class);
//            context.setMixInAnnotations(Array.class, DisableTypeInfo.class);
            
            //Default types for interfaces unknown to Jackson
            context.setMixInAnnotations(Bindings.class, UseSimpleBindings.class);
            context.setMixInAnnotations(PrincipalCollection.class, UseSimplePrincipalCollection.class);
            
            //serializers and typeinfo for shiro classes
            context.setMixInAnnotations(SimpleAuthenticationInfo.class, UseTypeInfoForCredentials.class);
            context.setMixInAnnotations(SimpleHash.class, SimpleHashMixin.class);
            context.setMixInAnnotations(ByteSource.class, UseSimpleByteSource.class);
            context.setMixInAnnotations(SimpleByteSource.class, SimpleByteSourceMixin.class);
            
            //and it's safer to use public interfaces on some classes
            context.setMixInAnnotations(ConstraintViolation.class, UseDefaultAutoDetect.class);
            context.setMixInAnnotations(ConstraintDescriptor.class, UseDefaultAutoDetect.class);
            context.setMixInAnnotations(Node.class, UseDefaultAutoDetect.class);
            
            
        }
 
开发者ID:CIDARLAB,项目名称:clotho3crud,代码行数:25,代码来源:JSON.java

示例2: updateUserPassword

import org.apache.shiro.crypto.hash.SimpleHash; //导入依赖的package包/类
/**
 * 更新当前用户密码
 * 
 * @param oldPassword 旧密码
 * @param newPassword 新密码
 * 
 */
//当修改成功后将shiro的认证缓存也更新,包正下次登录也不需要在次查询数据库
@CacheEvict(value="shiroAuthenticationCache",
		  	key="T(com.github.dactiv.showcase.common.SystemVariableUtils)." +
				"getSessionVariable()." +
				"getUser()." +
				"getUsername()")
public void updateUserPassword(String oldPassword, String newPassword) {
	User user = SystemVariableUtils.getSessionVariable().getUser();
	
	oldPassword = new SimpleHash("MD5", oldPassword.toCharArray()).toString();
	
	if (!user.getPassword().equals(oldPassword)) {
		throw new ServiceException("旧密码不正确.");
	}
	
	String temp = new SimpleHash("MD5",newPassword).toHex();
	userDao.updatePassword(user.getId(),temp);
	user.setPassword(temp); 
}
 
开发者ID:extion,项目名称:base-framework,代码行数:27,代码来源:AccountManager.java

示例3: getAccountByUsernameTest

import org.apache.shiro.crypto.hash.SimpleHash; //导入依赖的package包/类
/**
 * This test checks if the admin user exists in an initial database created by liquibase scripts.
 *
 * <p>The test also checks functionality of {@link AccountRepositoryImpl#getAccountByUsername(String)}
 * method.
 *
 * <p>Admin user must be found.
 */
@Test
public void getAccountByUsernameTest() {
    AccountEntity account = accountRepository.getAccountByUsername(entityManager, ADMIN_USERNAME);

    // must be admin
    assertNotNull(account);
    assertNotNull(account.getId());
    assertEquals(ADMIN_USERNAME, account.getUsername());
    assertNotNull(account.getPassword());
    assertNotNull(account.getPasswordSalt());
    assertEquals(true, account.getIsCredentialsExpired());

    // check password
    byte[] salt = Base64.decode(account.getPasswordSalt());
    String hashedPasswordBase64 = new SimpleHash(PersistenceRealm.HASH_ALGORITHM, ADMIN_PASSWORD, salt, PersistenceRealm.HASH_ITERATIONS).toBase64();
    assertEquals(hashedPasswordBase64, account.getPassword());
}
 
开发者ID:panifex,项目名称:panifex-platform,代码行数:26,代码来源:AccountRepositoryImplTest.java

示例4: encryptPassword

import org.apache.shiro.crypto.hash.SimpleHash; //导入依赖的package包/类
/**
 * 加密密码
 * @param realm
 */
public static BaseRealm encryptPassword(BaseRealm realm) {
	realm.setSalt(randomNumberGenerator.nextBytes().toHex());
	String credentialsSalt = realm.getUserName() + realm.getSalt();
	String newPassword = new SimpleHash(algorithmName, realm.getPassword(),
			ByteSource.Util.bytes(credentialsSalt), hashIterations).toHex();

	realm.setPassword(newPassword);
	return realm;
}
 
开发者ID:babymm,项目名称:mumu,代码行数:14,代码来源:PasswordHelper.java

示例5: encryptPassword

import org.apache.shiro.crypto.hash.SimpleHash; //导入依赖的package包/类
public void encryptPassword(User user) {

        user.setSalt(randomNumberGenerator.nextBytes().toHex());

        String newPassword = new SimpleHash(
                algorithmName,
                user.getPassword(),
                ByteSource.Util.bytes(user.getCredentialsSalt()),
                hashIterations).toHex();

        user.setPassword(newPassword);
    }
 
开发者ID:melonlee,项目名称:LazyREST,代码行数:13,代码来源:PasswordUtil.java

示例6: encryptPassword

import org.apache.shiro.crypto.hash.SimpleHash; //导入依赖的package包/类
/**
 * 密码加密  md5(name+salt)
 *
 * @param admin
 */
public void encryptPassword(Admin admin) {

    admin.setSalt(randomNumberGenerator.nextBytes().toHex());
    String newPassword = new SimpleHash(
            algorithmName,
            admin.getPassword(),
            ByteSource.Util.bytes(admin.getCredentialsSalt()),
            hashIterations).toHex();
    admin.setPassword(newPassword);
}
 
开发者ID:melonlee,项目名称:LazyAdmin,代码行数:16,代码来源:PasswordHelper.java

示例7: passwdMD5

import org.apache.shiro.crypto.hash.SimpleHash; //导入依赖的package包/类
/**
 * 注册时对用户的密码进行加密
 * @param passwd 明文密码
 * @return 经过MD5加密后的密码
 */
public static String passwdMD5(String passwd){
	String saltSource = SysConst.SALTSOURCE;
	String algorithmName = "MD5";
	String credentials = passwd;
	Object salt = new Md5Hash(saltSource);
	int hashIterations = 1024;
	Object result = new SimpleHash(algorithmName, credentials, salt, hashIterations);
	return result.toString();
}
 
开发者ID:MarchMachao,项目名称:ZHFS-WEB,代码行数:15,代码来源:ShiroUtils.java

示例8: encryptPassword

import org.apache.shiro.crypto.hash.SimpleHash; //导入依赖的package包/类
public void encryptPassword(User user) {

        user.setSalt(randomNumberGenerator.nextBytes().toHex());

        String newPassword = new SimpleHash(
                algorithmName,
                user.getPassword(),
                ByteSource.Util.bytes(user.getCredentialsSalt()),
                hashIterations).toHex();
        user.setPassword(newPassword);
    }
 
开发者ID:liaojiacan,项目名称:zkAdmin,代码行数:12,代码来源:PasswordHelper.java

示例9: matchPassword

import org.apache.shiro.crypto.hash.SimpleHash; //导入依赖的package包/类
public boolean matchPassword(User user,String password){
    String calculatePassword = new SimpleHash(
            algorithmName,
            password,
            ByteSource.Util.bytes(user.getCredentialsSalt()),
            hashIterations).toHex();
    return user.getPassword().equals(calculatePassword);
}
 
开发者ID:liaojiacan,项目名称:zkAdmin,代码行数:9,代码来源:PasswordHelper.java

示例10: doCredentialsMatch

import org.apache.shiro.crypto.hash.SimpleHash; //导入依赖的package包/类
@Override
public boolean doCredentialsMatch(AuthenticationToken token, AuthenticationInfo info) {
    UsernamePasswordToken usernamePasswordToken= (UsernamePasswordToken) token;
    String password=new String(usernamePasswordToken.getPassword());
    SimpleHash hash=new SimpleHash("md5",password,"1997password",3);

    String dbPassword= (String) info.getCredentials();
    return this.equals(hash.toString(),dbPassword);
}
 
开发者ID:fuyunwang,项目名称:SpringBootShiro,代码行数:10,代码来源:CredentialMatcher.java

示例11: testMD5

import org.apache.shiro.crypto.hash.SimpleHash; //导入依赖的package包/类
/**
 * testMD5
 * @Description: 参1:原有字符串,参2:盐,参3:散列次数
 * @return: void
 * @Author: BeautifulSoup
 * @Date: 2017年12月16日 下午12:16:46
 */
@Test
public void testMD5(){
	String source="123456";
	String salt="1997password";
	int hashIterations=3;
	SimpleHash md5hash=new SimpleHash("md5", source, salt, hashIterations);
	System.out.println(md5hash.toString());
}
 
开发者ID:fuyunwang,项目名称:ShiroDemo,代码行数:16,代码来源:AuthenticationTest.java

示例12: shiroPwd

import org.apache.shiro.crypto.hash.SimpleHash; //导入依赖的package包/类
/**
 * shiro密码
 * @param str
 * @param salt
 * @return
 */
public final static String shiroPwd(String str,String salt){
    String credentials = str;
    ByteSource credentialsSalt = ByteSource.Util.bytes(salt);
    String obj = new SimpleHash(HASH_ALGORITHM, credentials, credentialsSalt, HASH_INTERATIONS).toHex();
    return obj;
}
 
开发者ID:egojit8,项目名称:easyweb,代码行数:13,代码来源:MD5Util.java

示例13: getHashString

import org.apache.shiro.crypto.hash.SimpleHash; //导入依赖的package包/类
public static String getHashString(String secret, byte[] salt) {
	return (secret == null) ? null : new SimpleHash(HASH_ALGORITHM, secret, new SimpleByteSource(salt), HASH_ITERATIONS).toHex();
}
 
开发者ID:auslides,项目名称:stateless-shiro,代码行数:4,代码来源:HashHelper.java

示例14: encryptPassword

import org.apache.shiro.crypto.hash.SimpleHash; //导入依赖的package包/类
/**
 * 密码加密  md5(name+salt)
 *
 * @param user
 */
public void encryptPassword(User user) {

    user.setSalt(randomNumberGenerator.nextBytes().toHex());
    String newPassword = new SimpleHash(
            algorithmName,
            user.getPasswd(),
            ByteSource.Util.bytes(user.getCredentialsSalt()),
            hashIterations).toHex();
    user.setPasswd(newPassword);
}
 
开发者ID:melonlee,项目名称:PowerApi,代码行数:16,代码来源:PasswordHelper.java

示例15: testGeneratePassword

import org.apache.shiro.crypto.hash.SimpleHash; //导入依赖的package包/类
@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);
}
 
开发者ID:l81893521,项目名称:shiro-demo,代码行数:15,代码来源:PasswordTest.java


注:本文中的org.apache.shiro.crypto.hash.SimpleHash类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。