本文整理汇总了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);
}
示例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);
}
示例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());
}
示例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;
}
示例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);
}
示例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);
}
示例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();
}
示例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);
}
示例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);
}
示例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);
}
示例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());
}
示例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;
}
示例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();
}
示例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);
}
示例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);
}