org.mindrot.jbcrypt.BCrypt.checkpw()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(7.0k)|赞(0)|评价(0)|浏览(218)

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

BCrypt.checkpw介绍

[英]Check that a plaintext password matches a previously hashed one
[中]检查明文密码是否与以前的哈希密码匹配

代码示例

代码示例来源:origin: jenkinsci/jenkins

public boolean isPasswordValid(String encPass, String rawPass, Object obj) throws DataAccessException {
  return BCrypt.checkpw(rawPass,encPass);
}

代码示例来源:origin: SonarSource/sonarqube

@Override
public AuthenticationResult checkCredentials(UserDto user, String password) {
 if (!BCrypt.checkpw(password, user.getCryptedPassword())) {
  return new AuthenticationResult(false, "wrong password");
 }
 return new AuthenticationResult(true, "");
}

代码示例来源:origin: hierynomus/sshj

/**
 * Test method for 'BCrypt.checkpw(String, String)'
 * expecting failure
 */
public void testCheckpw_failure() {
  System.out.print("BCrypt.checkpw w/ bad passwords: ");
  for (int i = 0; i < test_vectors.length; i++) {
    int broken_index = (i + 4) % test_vectors.length;
    String plain = test_vectors[i][0];
    String expected = test_vectors[broken_index][2];
    assertFalse(BCrypt.checkpw(plain, expected));
    System.out.print(".");
  }
  System.out.println("");
}

代码示例来源:origin: hierynomus/sshj

/**
 * Test method for 'BCrypt.checkpw(String, String)'
 * expecting success
 */
public void testCheckpw_success() {
  System.out.print("BCrypt.checkpw w/ good passwords: ");
  for (int i = 0; i < test_vectors.length; i++) {
    String plain = test_vectors[i][0];
    String expected = test_vectors[i][2];
    assertTrue(BCrypt.checkpw(plain, expected));
    System.out.print(".");
  }
  System.out.println("");
}

代码示例来源:origin: hierynomus/sshj

/**
 * Test for correct hashing of non-US-ASCII passwords
 */
public void testInternationalChars() {
  System.out.print("BCrypt.hashpw w/ international chars: ");
  String pw1 = "\u2605\u2605\u2605\u2605\u2605\u2605\u2605\u2605";
  String pw2 = "????????";
  String h1 = BCrypt.hashpw(pw1, BCrypt.gensalt());
  assertFalse(BCrypt.checkpw(pw2, h1));
  System.out.print(".");
  String h2 = BCrypt.hashpw(pw2, BCrypt.gensalt());
  assertFalse(BCrypt.checkpw(pw1, h2));
  System.out.print(".");
  System.out.println("");
}

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

public AuthenticatedUser authenticate(final Map<String, String> credentials) throws AuthenticationException {
  final Vertex user;
  if (!credentials.containsKey(PROPERTY_USERNAME)) throw new IllegalArgumentException(String.format("Credentials must contain a %s", PROPERTY_USERNAME));
  if (!credentials.containsKey(PROPERTY_PASSWORD)) throw new IllegalArgumentException(String.format("Credentials must contain a %s", PROPERTY_PASSWORD));
  final String username = credentials.get(PROPERTY_USERNAME);
  final String password = credentials.get(PROPERTY_PASSWORD);
  final CredentialTraversal<Vertex,Vertex> t = credentialStore.users(username);
  if (!t.hasNext())
    throw new AuthenticationException("Username and/or password are incorrect");
  user = t.next();
  if (t.hasNext()) {
    logger.warn("There is more than one user with the username [{}] - usernames must be unique", username);
    throw new AuthenticationException("Username and/or password are incorrect");
  }
  final String hash = user.value(PROPERTY_PASSWORD);
  if (!BCrypt.checkpw(password, hash))
    throw new AuthenticationException("Username and/or password are incorrect");
  return new AuthenticatedUser(username);
}

代码示例来源:origin: syncthing/syncthing-android

boolean passwordOk;
try {
  passwordOk = !TextUtils.isEmpty(pw) && BCrypt.checkpw(apikey, pw);
} catch (IllegalArgumentException e) {
  Log.w(TAG, "Malformed password", e);

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

public boolean verifyPassword(char[] password, String hash) {
  if (null == password) {
    return false;
  }
  try {
    return BCrypt.checkpw(password, hash);
  } catch (Exception e) {
    return false;
  }
}

代码示例来源:origin: info.magnolia/magnolia-core

public static boolean matchBCrypted(String candidate, String hash) {
  // Check that an unencrypted password matches one that has
  // previously been hashed
  return BCrypt.checkpw(candidate, hash);
}

代码示例来源:origin: IQSS/dataverse

@Override
  public boolean check(String plainText, String hashed) {
    try {
      return BCrypt.checkpw(plainText, hashed);
    } catch (java.lang.IllegalArgumentException iae ) {
      // the password was probably not hashed using bcrypt.
      return false;
    }
  }
};

代码示例来源:origin: com.intrbiz.bergamot/bergamot-model

public boolean verifyPassword(String plainPassword)
{
  if (plainPassword == null || this.passwordHash == null) return false;
  return BCrypt.checkpw(plainPassword, this.passwordHash);
}

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

public boolean verifyPassword(String password, String hash) {
  if (null == password) {
    return false;
  }
  try {
    return BCrypt.checkpw(password, hash);
  } catch (Exception e) {
    return false;
  }
}

代码示例来源:origin: org.actframework/act

public boolean verifyPassword(String password, String hash) {
  if (null == password) {
    return false;
  }
  try {
    return BCrypt.checkpw(password, hash);
  } catch (Exception e) {
    return false;
  }
}

代码示例来源:origin: com.intoverflow.booster/booster-core

/**
 * 校验参数提供的密码的正确性
 *
 * @param tryPassword 待校验密码值
 * @param salt        密码盐值
 * @param password    密码密文
 * @return
 */
default boolean matches(String tryPassword, String salt, String password) {
  // 换用 BCrypt 淘汰 md5
  return BCrypt.checkpw(tryPassword + salt, password);
}

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

public boolean verifyPassword(char[] password, char[] hash) {
  if (null == password) {
    return false;
  }
  try {
    return BCrypt.checkpw(password, new String(hash));
  } catch (Exception e) {
    return false;
  }
}

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

/**
 * Check that a plaintext password matches a previously hashed
 * one
 * @param plaintext    the plaintext password to verify
 * @param hashed    the previously-hashed password
 * @return    true if the passwords match, false otherwise
 */
public static boolean checkpw(String plaintext, String hashed) {
  return checkpw(plaintext.toCharArray(), hashed);
}

代码示例来源:origin: net.liftweb/lift-util

/**
   * @see org.mindrot.jbcrypt.BCrypt#checkpw(String,String)
   */
  @Deprecated
  public static boolean checkpw(String plaintext, String hashed) {
    return org.mindrot.jbcrypt.BCrypt.checkpw(plaintext, hashed);
  }
}

代码示例来源:origin: org.actframework/act

/**
 * Check that a plaintext password matches a previously hashed
 * one
 * @param plaintext    the plaintext password to verify
 * @param hashed    the previously-hashed password
 * @return    true if the passwords match, false otherwise
 */
public static boolean checkpw(String plaintext, String hashed) {
  return checkpw(plaintext.toCharArray(), hashed);
}

代码示例来源:origin: org.actframework/act

public boolean verifyPassword(char[] password, char[] hash) {
  if (null == password) {
    return false;
  }
  try {
    return BCrypt.checkpw(password, new String(hash));
  } catch (Exception e) {
    return false;
  }
}

代码示例来源:origin: qq53182347/liugh-parent

@Override
public void resetPassWord(User currentUser, JSONObject requestJson) throws Exception {
  if (!requestJson.getString("password").equals(requestJson.getString("rePassword"))) {
    throw  new BusinessException(PublicResultConstant.INVALID_RE_PASSWORD);
  }
  if(!BCrypt.checkpw(requestJson.getString("oldPassword"),currentUser.getPassword())){
    throw  new BusinessException(PublicResultConstant.INVALID_USERNAME_PASSWORD);
  }
  currentUser.setPassword(BCrypt.hashpw(requestJson.getString("password"),BCrypt.gensalt()));
  this.updateById(currentUser);
}

相关文章