class Athena::PasswordHasher::Native
inherits Reference
#
Hashes passwords with bcrypt, using the standard library's Crypto::Bcrypt type.
hasher = APH::Native.new
hash = hasher.hash "password" # => "$2a$13$..."
hasher.verify hash, "password" # => true
hasher.verify hash, "wrong_password" # => false
Bcrypt only uses the first 72 bytes of a password, and ignores everything after a NUL byte. Passwords longer than 72 bytes, or that contain a NUL byte, are therefore hashed with SHA-512 first, so that all of their bytes are taken into account.
Included modules
Athena::PasswordHasher::Interface
Constants#
COST_RANGE = Crypto::Bcrypt::COST_RANGE#
The range of supported cost values.
Constructors#
Methods#
#cost : Int32#
Returns the cost factor used to hash passwords. Each increment doubles the time it takes to hash a password.
#hash(plain_password : String) : String#
Returns the hash of the provided plain_password.
Raises an APH::Exception::InvalidPassword if the password is invalid, e.g. longer than MAX_PASSWORD_LENGTH.
#needs_rehash?(hashed_password : String) : Bool#
Returns true if the provided hashed_password would benefit from being re-hashed, e.g. because it was hashed with a different algorithm or cost.
#verify(hashed_password : String, plain_password : String) : Bool#
Returns true if the provided plain_password matches the hashed_password, otherwise false.