BCrypt :: Password Ruby

问题描述 投票:-2回答:2

我目前正在使用Ruby,但无法获得,之间有什么区别>>

def create_hash_digest(password)
  BCrypt::Password.create(password)
end

def verify_hash_digest(password)
  BCrypt::Password.new(password)
end

此示例摘自有关完整的Ruby on Rails的Udemy课程

[我目前正在使用Ruby,但无法获得,def create_hash_digest(password)BCrypt :: Password.create(password)end def verify_hash_digest(password)BCrypt :: ...有什么区别?]] >

[#create用于散列机密,返回BCrypt::Password实例,即加密

[#new用于使用存储的哈希中的数据解密BCrypt::Password实例。

include BCrypt
# hash a user's password
@password = Password.create("my grand secret")
@password #=> "$2a$12$C5.FIvVDS9W4AYZ/Ib37YuWd/7ozp1UaMhU28UKrfSxp2oDchbi3K"

# store it safely @user.update_attribute(:password, @password)

# read it back
@user.reload!
@db_password = Password.new(@user.password)

# compare it after retrieval
@db_password == "my grand secret" #=> true
@db_password == "a paltry guess" #=> false

#create将您的密码转换为哈希:

'my_password' ~> '$2a$12$C5.FIvVDS9W4AYZ/Ib37...' 

[#new转换回它时。

ruby bcrypt
2个回答
1
投票

[#create用于散列机密,返回BCrypt::Password实例,即加密


0
投票

#create将您的密码转换为哈希:

'my_password' ~> '$2a$12$C5.FIvVDS9W4AYZ/Ib37...' 
© www.soinside.com 2019 - 2024. All rights reserved.