当用户在 Drupal 中更改密码时获取明文形式的新密码?
在我的 Drupal 模块中,我试图连接用户更改密码的位置。我需要这个明文来做其他事情。
所以我做了基本的事情并使用了 tcauth_user_presave()。然后我更改了密码,这触发了日志记录功能。但是,当我查看日志时,提供的 &$edit
、$account
和 $category
变量不包含新密码明文。唯一可用的是旧密码(明文)和散列后的新密码。
当有人更改密码时,是否可以获取明文密码?如果重要的话,这就是 Drupal 7。
In my Drupal module I'm attempting to hook in where a user changes their password. I need this in cleartext for something else.
So I did the basic thing and used tcauth_user_presave()
. I then changed my password which triggered a logging function. However when I looked at the log the provided &$edit
, $account
, and $category
variables didn't contain the new password in cleartext. The only thing that was available was the old password (in cleartext) and the new password hashed.
Is there anyway to get the cleartext password when someone changes it? This is Drupal 7 if it matters.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
密码在 user_save()< 中进行哈希处理/a> 在调用 presave 挂钩之前。
然而,除了改变形式之外,似乎还有另一种选择。在 中调用 user_save() 之前user_profile_form_submit(),hook_field_attach_submit() 通过entity_form_submit_build_entity() 辅助函数调用。虽然它是一个字段钩子,但它确实接收完整的用户对象作为 $entity。
不确定这是否真的比更改表单更好,因为该钩子是为所有实体更改而调用的,而不仅仅是用户。
The password is hashed in user_save() before the presave hook is called.
Looks like there is another option than altering the form, however. Before user_save() is called in user_profile_form_submit(), hook_field_attach_submit() is invoked through the entity_form_submit_build_entity() helper function. Although it's a field hook, it does recieve the full user object as $entity.
Not sure if that is really the better than altering the form because the hook is invoked for all entity changes, not just users.
我不确定这是否是捕获它的最佳位置,但在 hook_form_alter 中可以使用纯文本输入:
更新:我做了一些更多的挖掘。我认为解决这个问题的方法是向 user_profile_form 添加另一个提交处理程序,确保在 user_profile_form_submit 之前将其添加到数组中。然后,在用户配置文件表单提交对密码进行编码之前,您就可以完全访问该密码。如果您需要更多详细信息,请发表评论。
I'm not sure if it's the best place to catch it, but the plain text input is available within hook_form_alter:
UPDATE: I did some more digging around. I think the way I'd tackle it would be to add another submit handler to user_profile_form, making sure to add it to the array before user_profile_form_submit. You'd then have full access to the password, before it gets encoded by user_profile_form_submit. Post a comment, if you need more details.
这是我的例子。对于我来说,读取新密码很有帮助。
This is my example. It's helpful in my case to read the new password.
在
hook_user_update()
上尝试一下Try this on
hook_user_update()