我在我的登录模型中实现了用于解密/加密用户密码(在加密版本中存储在cookie中)的函数。除非重新启动浏览器并尝试使用cookie以密码登录时,所有工作都正常。添加空格来加密密码?
解析器告诉我这是错误的密码,即使我可以看到它是正确的,当我回显出来。因此,我尝试了一个“strlen”来查看密码有多少个字符,并且它说32(!)。我能想到的唯一的事情就是(在这种情况下)已经添加了28个空白空间,这是无法用回声看到的。
我真的很感激,如果有人能告诉我发生了什么事以及如何解决它?
function decrypt($encrypedText) {
$key = "The secret key is";
$decryptedText = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, base64_decode($encrypedText), MCRYPT_MODE_ECB);
echo $decryptedText; // "abcd" <- what I put in
echo strlen($decryptedText); // 32 (?)
return $decryptedText;
}
你在哪里定义'$ decryptedText'?它没有在函数中分配,它既不是参数也不是全局的。 – andrewsi
[Everything](http://www.codinghorror.com/blog/2007/09/youre-probably-storing-passwords-incorrectly.html)你[是](http://stackoverflow.com/questions/1054022/最好的方式来存储在数据库中的密码)尝试[](http://stackoverflow.com/questions/947618/how-to-best-store-user-information-and-user-login-and -password)do是[wrong。](http://blog.moertel.com/articles/2006/12/15/never-store-passwords-in-a-database)请停止你正在做的事,并了解正确的密码存储和处理。 – DampeS8N
@ DampeS8N:这只是我现在学习cookie的一个实验。 – holyredbeard