class AttrPassword::BCrypt
The BCrypt
class
Public Instance Methods
crypt_password(password)
click to toggle source
Crypt the password
Arguments:
password: (String)
Example:
>> backend.crypt_password("P@ssw0rd") => "$2a$10$Ou0no1.WrBtZm2rF4Te7getynnENc2wESKZDLyJTmqnSPV1TEXZ8y"
# File lib/attr_password/bcrypt.rb, line 14 def crypt_password(password) # Get the BCrypt password bcrypt = ::BCrypt::Password.create(password) # Get the BCrypt string bcrypt.to_s end
validate_password(password, password_hash)
click to toggle source
Check if a password is valid
Arguments:
password_hash: (String) password: (String)
Example:
>> backend.crypt_password("P@ssw0rd", "$2a$10$Ou0no1.WrBtZm2rF4Te7getynnENc2wESKZDLyJTmqnSPV1TEXZ8y") => true
# File lib/attr_password/bcrypt.rb, line 32 def validate_password(password, password_hash) begin # Load the BCrypt password hash bcrypt = ::BCrypt::Password.new(password_hash) # Check if the password is valid bcrypt == password rescue => e return false end end