org.apache.shiro.authc.credential.HashedCredentialsMatcher.setHashIterations()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(9.2k)|赞(0)|评价(0)|浏览(150)

本文整理了Java中org.apache.shiro.authc.credential.HashedCredentialsMatcher.setHashIterations()方法的一些代码示例,展示了HashedCredentialsMatcher.setHashIterations()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HashedCredentialsMatcher.setHashIterations()方法的具体详情如下:
包路径:org.apache.shiro.authc.credential.HashedCredentialsMatcher
类名称:HashedCredentialsMatcher
方法名:setHashIterations

HashedCredentialsMatcher.setHashIterations介绍

[英]Sets the number of times a submitted AuthenticationToken's credentials will be hashed before comparing to the credentials stored in the system.

Unless overridden, the default value is 1, meaning a normal single hash execution will occur.

If this argument is less than 1 (i.e. 0 or negative), the default value of 1 is applied. There must always be at least 1 hash iteration (otherwise there would be no hash).
[中]设置在与存储在系统中的凭据进行比较之前,对提交的AuthenticationToken的凭据进行哈希处理的次数。
除非重写,否则默认值为1,这意味着将执行正常的单个哈希。
如果此参数小于1(即0或负值),则应用默认值1。必须始终至少有一个哈希迭代(否则将没有哈希)。

代码示例

代码示例来源:origin: ityouknow/spring-boot-examples

/**
 * 凭证匹配器
 * (由于我们的密码校验交给Shiro的SimpleAuthenticationInfo进行处理了
 * )
 * @return
 */
@Bean
public HashedCredentialsMatcher hashedCredentialsMatcher(){
  HashedCredentialsMatcher hashedCredentialsMatcher = new HashedCredentialsMatcher();
  hashedCredentialsMatcher.setHashAlgorithmName("md5");//散列算法:这里使用MD5算法;
  hashedCredentialsMatcher.setHashIterations(2);//散列的次数,比如散列两次,相当于 md5(md5(""));
  return hashedCredentialsMatcher;
}

代码示例来源:origin: 527515025/springBoot

/**
 * HashedCredentialsMatcher,这个类是为了对密码进行编码的,
 * 防止密码在数据库里明码保存,当然在登陆认证的时候,
 * 这个类也负责对form里输入的密码进行编码。
 */
@Bean(name = "hashedCredentialsMatcher")
public HashedCredentialsMatcher hashedCredentialsMatcher() {
  HashedCredentialsMatcher credentialsMatcher = new HashedCredentialsMatcher();
  credentialsMatcher.setHashAlgorithmName("MD5");
  credentialsMatcher.setHashIterations(2);
  credentialsMatcher.setStoredCredentialsHexEncoded(true);
  return credentialsMatcher;
}

代码示例来源:origin: killbill/killbill

public static CredentialsMatcher getCredentialsMatcher(final SecurityConfig securityConfig) {
    // This needs to be in sync with DefaultTenantDao
    final HashedCredentialsMatcher credentialsMatcher = new HashedCredentialsMatcher(HASH_ALGORITHM_NAME);
    // base64 encoding, not hex
    credentialsMatcher.setStoredCredentialsHexEncoded(false);
    credentialsMatcher.setHashIterations(securityConfig.getShiroNbHashIterations());

    return credentialsMatcher;
  }
}

代码示例来源:origin: stylefeng/Guns

/**
   * 设置认证加密方式
   */
  @Override
  public void setCredentialsMatcher(CredentialsMatcher credentialsMatcher) {
    HashedCredentialsMatcher md5CredentialsMatcher = new HashedCredentialsMatcher();
    md5CredentialsMatcher.setHashAlgorithmName(ShiroKit.hashAlgorithmName);
    md5CredentialsMatcher.setHashIterations(ShiroKit.hashIterations);
    super.setCredentialsMatcher(md5CredentialsMatcher);
  }
}

代码示例来源:origin: stylefeng/Guns

/**
 * api登录接口,通过账号密码获取token
 */
@RequestMapping("/auth")
public Object auth(@RequestParam("username") String username,
          @RequestParam("password") String password) {
  //封装请求账号密码为shiro可验证的token
  UsernamePasswordToken usernamePasswordToken = new UsernamePasswordToken(username, password.toCharArray());
  //获取数据库中的账号密码,准备比对
  User user = userMapper.getByAccount(username);
  String credentials = user.getPassword();
  String salt = user.getSalt();
  ByteSource credentialsSalt = new Md5Hash(salt);
  SimpleAuthenticationInfo simpleAuthenticationInfo = new SimpleAuthenticationInfo(
      new ShiroUser(), credentials, credentialsSalt, "");
  //校验用户账号密码
  HashedCredentialsMatcher md5CredentialsMatcher = new HashedCredentialsMatcher();
  md5CredentialsMatcher.setHashAlgorithmName(ShiroKit.hashAlgorithmName);
  md5CredentialsMatcher.setHashIterations(ShiroKit.hashIterations);
  boolean passwordTrueFlag = md5CredentialsMatcher.doCredentialsMatch(
      usernamePasswordToken, simpleAuthenticationInfo);
  if (passwordTrueFlag) {
    HashMap<String, Object> result = new HashMap<>();
    result.put("token", JwtTokenUtil.generateToken(String.valueOf(user.getUserId())));
    return result;
  } else {
    return new ErrorResponseData(500, "账号密码错误!");
  }
}

代码示例来源:origin: magefree/mage

public boolean doCredentialsMatch(String name, String password) {
  HashedCredentialsMatcher matcher = new HashedCredentialsMatcher(this.hashAlgorithm);
  matcher.setHashIterations(this.hashIterations);
  AuthenticationToken token = new UsernamePasswordToken(name, password);
  AuthenticationInfo info = new SimpleAuthenticationInfo(this.name,
      ByteSource.Util.bytes(Base64.decode(this.password)),
      ByteSource.Util.bytes(Base64.decode(this.salt)), "");
  return matcher.doCredentialsMatch(token, info);
}

代码示例来源:origin: stackoverflow.com

final int iterations = 50000;

AuthenticationToken authToken = ...;
SaltedAuthenticationInfo saltedAuthInfo = ...;

HashedCredentialsMatcher authenticator = 
   new HashedCredentialsMatcher(Sha256Hash.ALGORITHM_NAME);
authenticator.setHashIterations(iterations);

final boolean successfulAuthentication = 
   authenticator.doCredentialsMatch(authToken, saltedAuthInfo);

代码示例来源:origin: org.neo4j/neo4j-security-enterprise

public HashedCredentialsMatcher getHashedCredentialsMatcher()
{
  if ( hashedCredentialsMatcher == null )
  {
    hashedCredentialsMatcher = new HashedCredentialsMatcher( HASH_ALGORITHM );
    hashedCredentialsMatcher.setHashIterations( HASH_ITERATIONS );
  }
  return hashedCredentialsMatcher;
}

代码示例来源:origin: lfz757077613/MyBlog

@Bean
public HashedCredentialsMatcher hashedCredentialsMatcher() {
  HashedCredentialsMatcher hashedCredentialsMatcher = new HashedCredentialsMatcher();
  hashedCredentialsMatcher.setHashAlgorithmName("MD5");
  hashedCredentialsMatcher.setHashIterations(5);
  return hashedCredentialsMatcher;
}

代码示例来源:origin: lcw2004/one

/**
 * 设定密码校验的Hash算法与迭代次数
 */
@PostConstruct
public void initCredentialsMatcher() {
  HashedCredentialsMatcher matcher = new HashedCredentialsMatcher(PasswordUtils.HASH_ALGORITHM);
  matcher.setHashIterations(PasswordUtils.HASH_INTERATIONS);
  setCredentialsMatcher(matcher);
}

代码示例来源:origin: wangxinforme/sc

/**
 * 设定Password校验的Hash算法与迭代次数.
 */
@PostConstruct
public void initCredentialsMatcher() {
  HashedCredentialsMatcher matcher = new HashedCredentialsMatcher("SHA-1");
  matcher.setHashIterations(1024);
  setCredentialsMatcher(matcher);
}

代码示例来源:origin: java-aodeng/hope-plus

/**
 * 凭证匹配器
 * )
 * @return
 */
@Bean
public HashedCredentialsMatcher hashedCredentialsMatcher(){
  HashedCredentialsMatcher hashedCredentialsMatcher = new HashedCredentialsMatcher();
  hashedCredentialsMatcher.setHashAlgorithmName("md5");
  hashedCredentialsMatcher.setHashIterations(2);
  return hashedCredentialsMatcher;
}

代码示例来源:origin: com.haoxuer.discover/discover-common-user-hibernate

/**
 * 设定Password校验的Hash算法与迭代次数.
 */
@SuppressWarnings("static-access")
@PostConstruct
public void initCredentialsMatcher() {
 HashedCredentialsMatcher matcher = new HashedCredentialsMatcher(SecurityUtil.HASH_ALGORITHM);
 matcher.setHashIterations(SecurityUtil.HASH_INTERATIONS);
 setCredentialsMatcher(matcher);
}

代码示例来源:origin: wangxinforme/springboot-freemarker

/**
 * 设定Password校验的Hash算法与迭代次数.
 */
@PostConstruct
public void initCredentialsMatcher() {
  HashedCredentialsMatcher matcher = new HashedCredentialsMatcher("SHA-1");
  matcher.setHashIterations(1024);
  setCredentialsMatcher(matcher);
}

代码示例来源:origin: com.github.sogyf/goja-mvt

public AppDbRealm() {
  HashedCredentialsMatcher matcher = new HashedCredentialsMatcher(EncodeKit.HASH_ALGORITHM);
  matcher.setHashIterations(EncodeKit.HASH_INTERATIONS);
  setCredentialsMatcher(matcher);
}

代码示例来源:origin: com.ning.billing/killbill-tenant

public static CredentialsMatcher getCredentialsMatcher() {
    // This needs to be in sync with DefaultTenantDao
    final HashedCredentialsMatcher credentialsMatcher = new HashedCredentialsMatcher(HASH_ALGORITHM_NAME);
    // base64 encoding, not hex
    credentialsMatcher.setStoredCredentialsHexEncoded(false);
    credentialsMatcher.setHashIterations(HASH_ITERATIONS);

    return credentialsMatcher;
  }
}

代码示例来源:origin: yidao620c/SpringBootBucket

/**
 * 凭证匹配器 (由于我们的密码校验交给Shiro的SimpleAuthenticationInfo进行处理了
 * 所以我们需要修改下doGetAuthenticationInfo中的代码; @return
 */
@Bean
public HashedCredentialsMatcher hashedCredentialsMatcher() {
  HashedCredentialsMatcher hashedCredentialsMatcher = new HashedCredentialsMatcher();
  hashedCredentialsMatcher.setHashAlgorithmName("md5");// 散列算法:这里使用MD5算法;
  hashedCredentialsMatcher.setHashIterations(2);// 散列的次数,比如散列两次,相当于md5(md5(""));
  hashedCredentialsMatcher.setStoredCredentialsHexEncoded(true);//表示是否存储散列后的密码为16进制,需要和生成密码时的一样,默认是base64;
  return hashedCredentialsMatcher;
}

代码示例来源:origin: yidao620c/SpringBootBucket

/**
 * 设置认证加密方式
 */
@Override
public void setCredentialsMatcher(CredentialsMatcher credentialsMatcher) {
  HashedCredentialsMatcher md5CredentialsMatcher = new HashedCredentialsMatcher();
  md5CredentialsMatcher.setHashAlgorithmName(ShiroKit.HASH_ALGORITHM_NAME);
  md5CredentialsMatcher.setHashIterations(ShiroKit.HASH_ITERATIONS);
  super.setCredentialsMatcher(md5CredentialsMatcher);
}

代码示例来源:origin: TomChen001/xmanager

@Override
  public void afterPropertiesSet() throws Exception {
    Assert.notNull(passwordHash, "you must set passwordHash!");
    super.setHashAlgorithmName(passwordHash.getAlgorithmName());
    super.setHashIterations(passwordHash.getHashIterations());
    this.passwordRetryCache = cacheManager.getCache(retryLimitCacheName);
  }
}

代码示例来源:origin: babylikebird/common-admin

@Override
  public void setCredentialsMatcher(CredentialsMatcher credentialsMatcher) {
    HashedCredentialsMatcher hashedCredentialsMatcher = new HashedCredentialsMatcher();
    hashedCredentialsMatcher.setHashAlgorithmName(ShiroKit.hashAlgorithmName);
    hashedCredentialsMatcher.setHashIterations(ShiroKit.hashIterations);
    super.setCredentialsMatcher(hashedCredentialsMatcher);
  }
}

相关文章