Zend_Auth setCredentialTreatment 处理
我使用 Zend_Auth
和 setCredentialTreatment
来设置哈希方法和盐。我看到所有示例都在执行类似的操作,其中 salt
似乎是作为文本插入的。
->setCredentialTreatment('SHA1(CONCAT(?,salt))'
但我的盐存储在数据库中。我可以先检索它,然后在 setCredentialTreatment
中使用它,但有没有办法可以定义它直接作为字段名称,因此 setCredentialTreatment
会知道从该字段获取它,就像我们为用户名或密码定义字段名称的方式一样
->setCredentialColumn('password')
我遇到的一个附带问题是我我想使用 SHA512 而不是 SHA1。这可能吗?我看到的所有示例都使用 SHA1,
我应该说我对 zend 还很陌生,并且正在移植现有的应用程序,所以请放心使用。答案。
I'm using Zend_Auth
with setCredentialTreatment
to set the hash method and salt. I see all examples doing something like this, where the salt
seems to be inserted as a text.
->setCredentialTreatment('SHA1(CONCAT(?,salt))'
but my salt is stored in the database. I could retrieve it first then use it in setCredentialTreatment
but is there a way I could define it directly as a field name, so setCredentialTreatment
would know to get it from that field? sort of like the way we define the field name for the username or password
->setCredentialColumn('password')
A side issue I'm having is that I'd like to use SHA512 not SHA1. Is this possible or is it not available? All the examples I see using SHA1.
I should say I'm fairly new to zend and am porting an existing application, so please go easy on me with the answers.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您给出的示例确实使用了数据库中存储的盐。只要盐存储在名为“盐”的字段中的每一行中,它就可以工作。如果盐不在数据库中而是在 PHP 变量中,则代码将更像:
至于使用 SHA512,这可能有点棘手。假设你使用 MySQL,在这种情况下 SHA1() 是一个 MySQL 函数,据我所知,MySQL 没有 SHA512 函数,PHP 也没有(编辑:我对后者错了,请参阅评论)。因此,您必须实现自己的 PHP SHA512 函数,首先从数据库中加载用户的盐,对结果进行哈希处理,并且不对 setCredentialTreatment 中的变量执行任何操作。
正如另一个答案所建议的,您可能想为此编写自己的 Zend_Auth_Adapter 。身份验证适配器是一个处理身份验证的类,大概在您使用 Zend_Auth_Adapter_DbTable 时。您可以在手册中找到有关身份验证适配器的更多信息: http:// /framework.zend.com/manual/en/zend.auth.introduction.html
这是一个示例:
The example you've given does use the salt as stored in the database. It will work as long as the salt is stored in each row in a field called 'salt'. If the salt was not in the DB and in a PHP variable instead, the code would be something more like:
As for using SHA512, this might be a little trickier. Assuming you're using MySQL, SHA1() in this case is a MySQL function, and MySQL does not have a function for SHA512 as far as I can tell, and neither does PHP (edit: I was wrong about the latter, see comments). So you'll have to implement your own PHP SHA512 function, load the salt for the user out of the DB first, hash the result and not do anything to the variable in setCredentialTreatment.
As the other answer suggested you might want to write your own Zend_Auth_Adapter for this. An auth adapter is a class that handles authentication, presumably at the moment you're using Zend_Auth_Adapter_DbTable. You can find some more info about auth adapters in the manual: http://framework.zend.com/manual/en/zend.auth.introduction.html
Here's an example:
您可以编写自己的
Zend_Auth_Adapter
。You can write your own
Zend_Auth_Adapter
.