has_secure_password是否使用任何形式的盐渍? [英] Does has_secure_password use any form of salting?

查看:111
本文介绍了has_secure_password是否使用任何形式的盐渍?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 has_secure_password 将加密密码存储在数据库中。如果 has_secure_password 使用任何形式的盐渍,我在互联网上找不到。如果它使用盐渍,它是如何工作的?任何人都可以澄清这一点吗?

I want to use has_secure_password to store encrypted passwords in the database. I can't find on the the internet if has_secure_password uses any form of salting. If it uses salting, how does it works? Can anyone clarify this for me?

Thijs

推荐答案

has_secure_password 使用 bcrypt-ruby bcrypt-ruby 为您自动处理盐的储存和生成。来自 bcrypt-ruby 的典型散列如下所示: $ 2a $ 10 $ 4wXszTTd7ass8j5ZLpK / 7.ywXXgDh7XPNmzfIWeZC1dMGpFghd92e 。这个哈希在内部使用以下函数进行拆分:

has_secure_password uses bcrypt-ruby. bcrypt-ruby automatically handles the storage and generation of salts for you. A typical hash from bcrypt-ruby looks like this: $2a$10$4wXszTTd7ass8j5ZLpK/7.ywXXgDh7XPNmzfIWeZC1dMGpFghd92e. This hash is split internally using the following function:

def split_hash(h)
  _, v, c, mash = h.split('$')
  return v, c.to_i, h[0, 29].to_str, mash[-31, 31].to_str
end

对于示例哈希,此函数产生:

For the example hash this function yields:


  • 版本:2a

  • 费用:10

  • salt:$ 2a $ 10 $ 4wXszTTd7ass8j5ZLpK / 7。

  • 哈希:ywXXgDh7XPNmzfIWeZC1dMGpFghd92e

  • version: 2a
  • cost: 10
  • salt: $2a$10$4wXszTTd7ass8j5ZLpK/7.
  • hash: ywXXgDh7XPNmzfIWeZC1dMGpFghd92e

== 功能 BCrypt :: Password 提取盐并将其应用于传递的字符串:

The ==-function of BCrypt::Password extracts the salt and applies it to the passed string:

BCrypt::Password.create('bla') == 'bla' # => true

这篇关于has_secure_password是否使用任何形式的盐渍?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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