我在 Linux 中为两个应用程序使用 Apache 库作为哈希密码。其中之一是 Pure-Ftp,另一个是我的应用程序。我手动将散列密码保存在 Pure-Ftp 密码文件中,它工作正常,用户可以使用给定的用户/密码使用 Ftp。
在我的应用程序中,我想对用户进行身份验证,但是没有任何 checkPassword(clearTextPassword, hashedPassword) 函数。
import org.apache.commons.codec.digest.Crypt;
...
...
...
String hashedValue = Crypt.crypt(clearTextPassword);
..
最佳答案
要验证密码,您可以使用 savedHashedPassword 作为盐对给定的简单密码进行哈希处理:
private static boolean checkPassword(String password, String hashedPassword) {
String tmpHashedPassword = Crypt.crypt(password, hashedPassword);
return hashedPassword.equalsIgnoreCase(tmpHashedPassword);
Crypt.crypt(password) 使用最强的 crypt(3) 算法计算摘要。使用随机盐和默认算法(当前为 SHA-512)。
关于java - 如何在 Java 中使用 SHA1 对用户进行身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42023638/