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

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

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

HashedCredentialsMatcher.getHashIterations介绍

[英]Returns 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 hash execution will occur.
[中]返回提交的AuthenticationToken的凭据在与存储在系统中的凭据进行比较之前被哈希的次数。
除非重写,否则默认值为1,这意味着将执行正常的哈希。

代码示例

代码示例来源:origin: apache/shiro

/**
 * Hash the provided {@code token}'s credentials using the salt stored with the account if the
 * {@code info} instance is an {@code instanceof} {@link SaltedAuthenticationInfo SaltedAuthenticationInfo} (see
 * the class-level JavaDoc for why this is the preferred approach).
 * <p/>
 * If the {@code info} instance is <em>not</em>
 * an {@code instanceof} {@code SaltedAuthenticationInfo}, the logic will fall back to Shiro 1.0
 * backwards-compatible logic:  it will first check to see {@link #isHashSalted() isHashSalted} and if so, will try
 * to acquire the salt from {@link #getSalt(AuthenticationToken) getSalt(AuthenticationToken)}.  See the class-level
 * JavaDoc for why this is not recommended.  This 'fallback' logic exists only for backwards-compatibility.
 * {@code Realm}s should be updated as soon as possible to return {@code SaltedAuthenticationInfo} instances
 * if account credentials salting is enabled (highly recommended for password-based systems).
 *
 * @param token the submitted authentication token from which its credentials will be hashed
 * @param info  the stored account data, potentially used to acquire a salt
 * @return the token credentials hash
 * @since 1.1
 */
protected Object hashProvidedCredentials(AuthenticationToken token, AuthenticationInfo info) {
  Object salt = null;
  if (info instanceof SaltedAuthenticationInfo) {
    salt = ((SaltedAuthenticationInfo) info).getCredentialsSalt();
  } else {
    //retain 1.0 backwards compatibility:
    if (isHashSalted()) {
      salt = getSalt(token);
    }
  }
  return hashProvidedCredentials(token.getCredentials(), salt, getHashIterations());
}

代码示例来源:origin: org.apache.shiro/shiro-core

/**
 * Hash the provided {@code token}'s credentials using the salt stored with the account if the
 * {@code info} instance is an {@code instanceof} {@link SaltedAuthenticationInfo SaltedAuthenticationInfo} (see
 * the class-level JavaDoc for why this is the preferred approach).
 * <p/>
 * If the {@code info} instance is <em>not</em>
 * an {@code instanceof} {@code SaltedAuthenticationInfo}, the logic will fall back to Shiro 1.0
 * backwards-compatible logic:  it will first check to see {@link #isHashSalted() isHashSalted} and if so, will try
 * to acquire the salt from {@link #getSalt(AuthenticationToken) getSalt(AuthenticationToken)}.  See the class-level
 * JavaDoc for why this is not recommended.  This 'fallback' logic exists only for backwards-compatibility.
 * {@code Realm}s should be updated as soon as possible to return {@code SaltedAuthenticationInfo} instances
 * if account credentials salting is enabled (highly recommended for password-based systems).
 *
 * @param token the submitted authentication token from which its credentials will be hashed
 * @param info  the stored account data, potentially used to acquire a salt
 * @return the token credentials hash
 * @since 1.1
 */
protected Object hashProvidedCredentials(AuthenticationToken token, AuthenticationInfo info) {
  Object salt = null;
  if (info instanceof SaltedAuthenticationInfo) {
    salt = ((SaltedAuthenticationInfo) info).getCredentialsSalt();
  } else {
    //retain 1.0 backwards compatibility:
    if (isHashSalted()) {
      salt = getSalt(token);
    }
  }
  return hashProvidedCredentials(token.getCredentials(), salt, getHashIterations());
}

代码示例来源:origin: com.gitee.zhaohuihua/bdp-general-web

@Override
public String create(String id, String password) {
  String algorithm = hashedCredentialsMatcher.getHashAlgorithmName();
  int iterations = hashedCredentialsMatcher.getHashIterations();
  // String salt = PasswordShiro.salt(id);
  String salt = null;
  SimpleHash hash = new SimpleHash(algorithm, password, salt, iterations);
  return hash.toHex();
}

代码示例来源:origin: com.gitee.qdbp/qdbp-base-ctl

@Override
public String create(String id, String password) {
  String algorithm = hashedCredentialsMatcher.getHashAlgorithmName();
  int iterations = hashedCredentialsMatcher.getHashIterations();
  // String salt = PasswordShiro.salt(id);
  String salt = null;
  SimpleHash hash = new SimpleHash(algorithm, password, salt, iterations);
  return hash.toHex();
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.shiro

/**
 * Hash the provided {@code token}'s credentials using the salt stored with the account if the
 * {@code info} instance is an {@code instanceof} {@link SaltedAuthenticationInfo SaltedAuthenticationInfo} (see
 * the class-level JavaDoc for why this is the preferred approach).
 * <p/>
 * If the {@code info} instance is <em>not</em>
 * an {@code instanceof} {@code SaltedAuthenticationInfo}, the logic will fall back to Shiro 1.0
 * backwards-compatible logic:  it will first check to see {@link #isHashSalted() isHashSalted} and if so, will try
 * to acquire the salt from {@link #getSalt(AuthenticationToken) getSalt(AuthenticationToken)}.  See the class-level
 * JavaDoc for why this is not recommended.  This 'fallback' logic exists only for backwards-compatibility.
 * {@code Realm}s should be updated as soon as possible to return {@code SaltedAuthenticationInfo} instances
 * if account credentials salting is enabled (highly recommended for password-based systems).
 *
 * @param token the submitted authentication token from which its credentials will be hashed
 * @param info  the stored account data, potentially used to acquire a salt
 * @return the token credentials hash
 * @since 1.1
 */
protected Object hashProvidedCredentials(AuthenticationToken token, AuthenticationInfo info) {
  Object salt = null;
  if (info instanceof SaltedAuthenticationInfo) {
    salt = ((SaltedAuthenticationInfo) info).getCredentialsSalt();
  } else {
    //retain 1.0 backwards compatibility:
    if (isHashSalted()) {
      salt = getSalt(token);
    }
  }
  return hashProvidedCredentials(token.getCredentials(), salt, getHashIterations());
}

相关文章