Skip to content

class Athena::PasswordHasher::Factory
inherits Reference #

Returns the APH::Interface configured for a user, based on its type.

Password hashers are configured by type, or by name for an APH::PasswordHasherAwareInterface user to choose them. A type matches its subtypes and includers too, and the first hasher whose type matches a user is used. Types may be provided as is, or as their fully qualified name.

factory = APH::Factory.new({
  AdminUser                               => APH::Native.new(cost: 15),
  APH::PasswordAuthenticatedUserInterface => APH::Native.new,
  "strong"                                => APH::Native.new(cost: 16),
})

factory.password_hasher AdminUser.new # => The cost 15 hasher
factory.password_hasher User.new      # => The default hasher
factory.password_hasher "strong"      # => The cost 16 hasher

Note

The configured types of a generic user type are only matched by the name of its instantiation, e.g. "GenericUser(Int32)".

Included modules

Athena::PasswordHasher::FactoryInterface

Constructors#

.new(password_hashers : Hash(K, V)) forall K, V#

View source

Methods#

#password_hasher(name : String) : APH::Interface#

Returns the password hasher with the provided name, which may also be the name of the type it is configured for.

Raises an APH::Exception::Runtime if no password hasher is configured with that name.

View source

#password_hasher(user : APH::PasswordAuthenticatedUserInterface) : APH::Interface#

Returns the password hasher to use for the provided user.

If the user is an APH::PasswordHasherAwareInterface that returns a hasher name, the hasher with that name is used. Otherwise, it is the first one whose type the user is an instance of.

Raises an APH::Exception::Runtime if no password hasher is configured for the user.

View source

#password_hasher(user : APH::PasswordHasherAwareInterface) : APH::Interface#

Returns the password hasher to use for the provided user.

If the user is an APH::PasswordHasherAwareInterface that returns a hasher name, the hasher with that name is used. Otherwise, it is the first one whose type the user is an instance of.

Raises an APH::Exception::Runtime if no password hasher is configured for the user.

View source