- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我不久前写了这段代码,现在我正在为一个新项目恢复它,但它似乎不起作用,我无法弄清楚为什么它不会验证哈希。
当注册第一个 passwordEncrypt() 函数时,运行的 2 个函数如下所示。
当尝试登录时调用 checkPassword() 函数,而不是登录并回显"is",而是进入回显“否”的部分。
所以,如果有新的眼睛可以看看,请提前多谢!
// Encrypt user password
function passwordEncrypt($password) {
// set the salt
$salt = substr(md5(time()), 0, 22);
// encrypt using blowfish with a load of 10
$password = crypt($password, '$2a$10$' . $salt);
// return the encrypted hash
return $password;
}
/*
Check password function when logging in
first we select the password from the supplied username from the database
// get the row and set the hash to the currect password from the database
//run the salts etc and check to see if the passwords match
*/
function checkPassword($userName, $password, $db){
$sql = 'SELECT password FROM users WHERE userName = :userName';
$stmt = $db->prepare($sql);
$stmt->bindValue(':userName', $userName, PDO::PARAM_STR);
$stmt->execute();
$numRows = $stmt->rowCount();
if ($numRows > 0) {
$row = $stmt->fetch();
$hash = $row['password'];
// run the hash function on $password
$fullSalt = substr($hash, 0, 29);
$new_hash = crypt($password, $fullSalt);
// Check that the password matches
if($hash == $new_hash) {
echo 'yes';
exit;
return true;
} else {
echo 'no';
exit;
return false;
}
} else {
echo 'way';
exit;
return false;
}
}
我已经注册了一个密码,然后尝试了它,这就是它返回的内容
密码:$2a$10$023d3086e8462207a1fecueWH4Ub40MWbQJ7F9输入:$2a$10$023d3086e8462207a1fecueWH4Ub40MWbQJ7F9hapWU3lYxlg3AAa没有
所以它在 hapWU3lYxlg3AAa 上添加
最佳答案
"column length is what? 40? 50? 60? other? $2a$10$023d3086e8462207a1fecueWH4Ub40MWbQJ7F9 implies being too short. – Fred -ii-"
和
"ah 45 in the database – Tom C"
给你。列的长度太短,需要为 60。
手册建议255。
稍作更正: password_hash()
上的手册建议使用 255。但是,最好实际使用 255,因为手册还建议将来记住并认为它是“一个不错的选择”。
您需要清除您的行,将您的列更改为 60 或更大,然后创建一个新的散列并再次登录。
$2a$10$023d3086e8462207a1fecueWH4Ub40MWbQJ7F9hapWU3lYxlg3AAa
长60
脚注:
据说有些人发现很难使用 crypt()
,使用 password_hash()
或兼容包(如果 PHP < 5.5)https://github.com/ircmaxell/password_compat/ 是实际上更容易。 选择权在你。
另请参阅 Stack 上的此问答:
关于php - Blowfish 加密 - 哈希已创建但不会验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36334498/
我似乎找不到差异的来源。我在这个在线解密工具中发现了这种差异 http://www.tools4noobs.com/online_tools/decrypt/ 我有一些加密的 Blowfish 数据,
C++ blowfish 支持加密少于 C# NET BlowfishC++ Blowfish<-- 在 C++ 和 C# 应用程序中,我加密了以下数组 byte response[6] =
我必须实现java密码空间填充。我正在尝试编写支持 Blowfish/CBC/space 模式的 Perl 代码的实现。我在Java Cipher列表中找不到相关模式,仅支持PCK5Padding和N
我正在使用 Blowfish 实现一个简单的密码存储。一切都很好,直到我尝试了几种不同的密码/ key 组合,并遇到了许多解密值仍然是垃圾的情况。 下面是一个演示该问题的独立类。我得到以下输出: 'A
我正在做一个关于图像加密的项目。我们在图像上使用河豚加密。根据 Paul Kocher 的代码 http://www.schneier.com/blowfish-download.html 。主要功能
在将此标记为重复之前,请理解我在 stackoverflow 上找不到任何关于河豚的有用信息。我正在尝试使用 Android Studio 使用河豚加密和解密字符串。我的加密似乎有效。但是当我尝试解密
我正在尝试通过Blowfish解密十六进制编码的字符串。但结果与正确的不同。 String s="a1d0534e4baf9e670bde8670caee8b87" String decKey = "
我今天一整天都在尝试找出如何读取二进制文件并对其进行解密。 在我的文件中,前 4 个字节描述文件格式,后 32 个字节是 header ,使用 Blowfish 加密。 所以我写了这段代码来做到这一点
我用 Blowfish 编码做了一些测试,发现了一些东西。编码后的字符串并不总是与源字符串一样长。有时会更短。 如果我想解码编码字符串,我需要在 openssl 函数中解码的长度: BF_cfb64_
我正在将 C++ TCP 客户端翻译成 C#。该客户端用于使用河豚对数组的 4 个字节进行编码。 C++ Blowfish C# Blowfish(C# NET) C++ BYTE respo
我正在尝试让一个 bowfish 函数用于简单的字符缓冲区。当我尝试解密加密缓冲区并在 EVP_CipherFinal_ex() 调用上失败时,程序失败。 #include #include #i
我正在用 Blowfish 算法加密我的文件,但我似乎对此一无所知。每当我尝试 Encipher() 时,它都会抛出一个异常,提示“无效长度”。我认为当它用 8 进行模数时,长度必须为零,我认为这
许多脚本语言(Python/PHP/等...)包含允许您使用 Blowfish 作为密码单向散列的功能(有时通过扩展)。我正在尝试为 C++ 找到类似的实现,但我遇到的一切都是加密/解密解决方案。 有
我一直在研究在 php 应用程序中保护密码的更好程序。形式上我会使用类似的东西(只是一个例子,不要开枪!): $salt = md5(rand() . md5(rand() . '$%E$%SDRT'
无法解密使用 Blowfish 在 Go 语言中加密的 Java 密文。 加密 import ( "testing" "golang.org/x/crypto/blowfish"
考虑以下执行 Blowfish 加密的方法: import javax.crypto.Cipher; import javax.crypto.Mac; import javax.crypto.spec
我们有一个类,它包装 BouncyCaSTLe(实际上是 Android 的 SpongyCaSTLe)Blowfish,以加密要传输的数据: public class BlowfishOutputS
Blowfish 能够进行强加密,并且可以使用最大 56 字节的 key (448 位 key )。 key 必须是 8 字节的倍数(最多 56)。 我想编写一个示例,它将自动填充和取消填充键的大小。
这是加密和解密消息的基本代码: #include #include #include //gcc cryptage.c -o cryptage -lcrypto int main(){ BF_K
我很难弄清楚如何使用 C# bouncycaSTLe 库来解密河豚 CTR 密文。由于缺少关于如何使用它的 BC 文档,我不知道如何使用它 我广泛搜索但没有在堆栈溢出中找到类似的东西,如果您有一些关于
我是一名优秀的程序员,十分优秀!