Class: SecurelyHashedAttributes::Coders::BCryptPasswordColumn
- Inherits:
-
Object
- Object
- SecurelyHashedAttributes::Coders::BCryptPasswordColumn
- Defined in:
- lib/securely_hashed_attributes/coders/bcrypt_password_column.rb
Overview
This coder serializes strings to BCrypt::Password
instances which, as the name suggests, are suitable handlers for passwords.
Constant Summary collapse
- RESCUE_ERRORS =
A list of errors to handle when loading
[ArgumentError, BCrypt::Errors::InvalidHash]
Class Method Summary collapse
-
.dump(str) ⇒ BCrypt::Password
Wrap the given data in the warm blanket of a
BCrypt::Password
. -
.load(digest) ⇒ BCrypt::Password, String
Takes a String digest generated by
bcrypt
and wraps it in a newBCrypt::Password
for functionality beyond that of a simpleString
.
Class Method Details
.dump(str) ⇒ BCrypt::Password
Wrap the given data in the warm blanket of a BCrypt::Password
10 11 12 |
# File 'lib/securely_hashed_attributes/coders/bcrypt_password_column.rb', line 10 def self.dump str BCrypt::Password.create str end |
.load(digest) ⇒ BCrypt::Password, String
Takes a String digest generated by bcrypt
and wraps it in a new BCrypt::Password
for functionality beyond that of a simple String
. If digest
is nil
, an empty string is returned. If bcrypt
does not recognize digest
as a valid hash, digest
itself is returned.
20 21 22 23 24 25 26 27 |
# File 'lib/securely_hashed_attributes/coders/bcrypt_password_column.rb', line 20 def self.load digest return '' if digest.nil? begin BCrypt::Password.new digest rescue *RESCUE_ERRORS digest end end |