使用隐窝,并验证 - 不知道它是如何工作的? [英] Using crypt, and verifying - not sure how it works?

查看:177
本文介绍了使用隐窝,并验证 - 不知道它是如何工作的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这实际上是两个问题:

1)我的理解是你确定什么类型的加密 crypt()使用您在盐中使用的字符数。例如:

1) My understanding is you determine what type of encryption crypt() uses by how many characters you use in the salt. For instance:

crypt('mypassword', someStringThatIs33CharsLong); // This would be blowfish?

2)一旦得到这些数据,我将如何在未来的日期验证用户输入?以下内容似乎不起作用:

2) Once I get this data, how do I verify it against user input at a future date? The following doesn't appear to work:

if (crypt($user_input, $encryptedinfo) == $encryptedinfo) {
   echo "Password verified!";
}

我在这里缺少什么?

推荐答案

当您使用crypt时,Salt(someStringThatIs33CharsLong)需要相同,才能加密其他内容并使其值相同。我使用这个用户名/密码登录,密码被调用

When you are using crypt the Salt (someStringThatIs33CharsLong) needs to be the same in order for you to encrypt something else and have the value the same. I have used this for username/password logins where the password is called with

crypt('password', 'aCrt45xaCrt45xaCrt45xaCrt45xaCrt4');

当您重新加密时,您需要使用相同的盐才能确保它是一样的。这可以通过存储在数据库中或静态地完成。

When you re encrypt you will need to use the same salt to make sure it is the same. This can be done by storing in the database or statically.

所以你的支票将变成

if (crypt($user_input, someStringThatIs33CharsLong) == $encryptedinfo) {
   echo "Password verified!";
}

这篇关于使用隐窝,并验证 - 不知道它是如何工作的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆