class

Authentication::Base

Inherits Reference / Object

Constructors

new(set_password_hash = "", set_password = "")

Create an instance

NOTE: You can set password hash with set_password_hash: "password_hash" or set password with set_password: "password"

Example:

authentication = Authentication::Base.new set_password_hash: "$2a$16$YXplcnR5dWlvcHFzZGZna.zN8.evmDPoNK.n.l6cx0YKKnw37jd9K"
authentication2 = Authentication::Base.new set_password: "$2a$16$YXplcnR5dWlvcHFzZGZna.zN8.evmDPoNK.n.l6cx0YKKnw37jd9K"
Source

Class methods

check_cost
Source
cost

Get cost

Example:

Authentication::Base.cost = 15 # => Bool(true)
Authentication::Base.cost      # => 15
Source
cost=(cost : Int32)

Set cost

Example:

Authentication::Base.cost = 15 # => Bool(true)
Authentication::Base.cost = 3  # raise CostTooLow("Cost too low, 4 minimum is required (current cost 3)") exception
Source

Instance methods

authenticate(password : String, set_password_hash = "") : Bool

Authenticate

NOTE: You can set the password_hash here with set_password_hash: password_hash

Example:

authentication = Authentication::Base.new set_password: test
authentication.authenticate "test"
Source
password=(password : String) : String

Set password

Example:

authentication = Authentication::Base.new
authentication.password = "test" # => "$2a$16$YXplcnR5dWlvcHFzZGZna.zN8.evmDPoNK.n.l6cx0YKKnw37jd9K"
Source
password_hash

Get password_hash

Example:

authentication = Authentication::Base.new set_password_hash: "$2a$16$YXplcnR5dWlvcHFzZGZna.zN8.evmDPoNK.n.l6cx0YKKnw37jd9K"
authentication.password_hash # => "$2a$16$YXplcnR5dWlvcHFzZGZna.zN8.evmDPoNK.n.l6cx0YKKnw37jd9K"
Source
password_hash=(set_password_hash : String) : String

Set password_hash

Example:

authentication = Authentication::Base.new
authentication.password_hash = "$2a$16$YXplcnR5dWlvcHFzZGZna.zN8.evmDPoNK.n.l6cx0YKKnw37jd9K"
Source