[[1], "long-random-string"]} 1 是用户 ID。什么是长随机字符串-6ren">
gpt4 book ai didi

ruby-on-rails - Rails/Devise session 中的管理员数据由什么组成?

转载 作者:行者123 更新时间:2023-12-03 11:50:28 27 4
gpt4 key购买 nike

Rails session 中的“数据”如下所示:

{"warden.user.user.key" => [[1], "long-random-string"]}

1 是用户 ID。什么是长随机字符串?

这是 Rails 还是 Devise 处理/使用的东西?

最佳答案

当您登录 user (设计模型名称 User),一个键 "warden.user.model_name.key"已创建,在您的情况下是 "warden.user.user.key" .

例如:

{ warden.user.user.key => [[1], "$2a$10$KItas1NKsvunK0O5w9ioWu"] }

在哪里
1id登录用户的。
$2a$10$KItas1NKsvunK0O5w9ioWu又名 long-random-string部分加密密码用户 ID 1 .

您可以通过访问 rails console 来验证这一点。并执行
User.find(1).encrypted_password  
## => "$2a$10$KItas1NKsvunK0O5w9ioWuWp4wbZ4iympYMqVCRmmvTGapktKqdMe"

更新

could you tell me a bit more about this partial encrypted password? why is it partial and not full?



要在评论中回答您的上述问题, Devise存储部分 encrypted_password在 session 中调用 authenticatable_salt方法。 Devise存储部分 encrypted_password因为它更可靠,而不是在 session 中公开完整的 encrypted_pa​​ssword(即使它是加密的)。这就是为什么前 30 个字符 [0,29]encrypted_password被提取并存储在 session 中。
  # A reliable way to expose the salt regardless of the implementation.
def authenticatable_salt
encrypted_password[0,29] if encrypted_password
end

您可以看到 的代码authenticatable_salt 这里。

where/when is it used? is it used by Devise, or by Rails, or both?



它由 Devise 使用用于验证特定用户是否登录的身份验证。理想的用例是,特定的 Rails 应用程序如何在请求新页面时跟踪用户的登录方式。由于 HTTP 请求是无状态的,因此无法判断给定的请求实际上来自登录的特定用户?这就是 session 很重要的原因,因为它们允许应用程序跟踪登录用户从一个请求到另一个请求,直到 session 过期。

关于ruby-on-rails - Rails/Devise session 中的管理员数据由什么组成?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23597718/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com