本文整理汇总了Java中org.apache.commons.codec.digest.Md5Crypt.apr1Crypt方法的典型用法代码示例。如果您正苦于以下问题:Java Md5Crypt.apr1Crypt方法的具体用法?Java Md5Crypt.apr1Crypt怎么用?Java Md5Crypt.apr1Crypt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.codec.digest.Md5Crypt
的用法示例。
在下文中一共展示了Md5Crypt.apr1Crypt方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: generateCode
import org.apache.commons.codec.digest.Md5Crypt; //导入方法依赖的package包/类
/**
* Generate unique code
*/
public static String generateCode(Participant p, ActionBeanContext context) {
String salt = context.getServletContext().getInitParameter(PARTICIPANTPOINTS_SALT_PARAM);
if (salt == null){
log.warn("The '"+PARTICIPANTPOINTS_SALT_PARAM+ "' is not configured as context param. Using the insecure, default salt");
salt = DEFAULT_SALT;
}
StringBuffer sb = new StringBuffer();
sb.append(p.getKarateka().getName());
sb.append(p.getKarateka().getSurname());
sb.append(p.getVanencompetition().getDate());
String hash = Md5Crypt.apr1Crypt(sb.toString(), salt);
return hash;
}
示例2: compareCredential
import org.apache.commons.codec.digest.Md5Crypt; //导入方法依赖的package包/类
/**
* Compare login and password with hash from htpsswd
*
* @param login
* @param password
* @return boolean
*/
public static boolean compareCredential(String login, String password) {
if (isSetup()) {
// Get salt from apr1 hashed by login
String salt = getSaltFromLogin(login);
String hash = Md5Crypt.apr1Crypt(password, salt);
if (dataHtpasswd.contains(login + ":" + hash)) {
return true;
}
}
return false;
}
示例3: PasswordEncrypt
import org.apache.commons.codec.digest.Md5Crypt; //导入方法依赖的package包/类
public PasswordEncrypt(final String key) {
final byte[] keyBytes = key.getBytes(US_ASCII);
this.md5 = Md5Crypt.md5Crypt(keyBytes.clone());
this.apr1 = Md5Crypt.apr1Crypt(keyBytes.clone());
this.sha256 = Sha2Crypt.sha256Crypt(keyBytes.clone());
this.sha512 = Sha2Crypt.sha512Crypt(keyBytes.clone());
Arrays.fill(keyBytes, (byte) 0);
}
示例4: checkPassword
import org.apache.commons.codec.digest.Md5Crypt; //导入方法依赖的package包/类
public static boolean checkPassword(final String crypted, final String key) {
String crypted2 = null;
if (crypted == null)
return false;
if (crypted.length() < 24)
return false;
if (crypted.charAt(0) != '$')
return false;
final int offset2ndDolar = crypted.indexOf('$', 1);
if (offset2ndDolar < 0)
return false;
final int offset3ndDolar = crypted.indexOf('$', offset2ndDolar + 1);
if (offset3ndDolar < 0)
return false;
final String salt = crypted.substring(0, offset3ndDolar + 1);
final byte[] keyBytes = key.getBytes(US_ASCII);
if (crypted.startsWith("$1$")) { // MD5
crypted2 = Md5Crypt.md5Crypt(keyBytes.clone(), salt);
} else if (crypted.startsWith("$apr1$")) { // APR1
crypted2 = Md5Crypt.apr1Crypt(keyBytes.clone(), salt);
} else if (crypted.startsWith("$5$")) { // SHA2-256
crypted2 = Sha2Crypt.sha256Crypt(keyBytes.clone(), salt);
} else if (crypted.startsWith("$6$")) { // SHA2-512
crypted2 = Sha2Crypt.sha512Crypt(keyBytes.clone(), salt);
}
Arrays.fill(keyBytes, (byte) 0);
if (crypted2 == null)
return false;
return crypted.equals(crypted2);
}
示例5: validateMd5Password
import org.apache.commons.codec.digest.Md5Crypt; //导入方法依赖的package包/类
private static boolean validateMd5Password(String hashed, String plain) {
String result = Md5Crypt.apr1Crypt(plain, hashed);
return hashed.equals(result);
}