class Authentication::Base
- Authentication::Base
- Reference
- Object
Defined in:
authentication.crConstructors
-
.new(set_password_hash = "", set_password = "")
Create an instance
Class Method Summary
- .check_cost : Bool
-
.cost
Get cost
-
.cost=(cost : Int32)
Set cost
Instance Method Summary
-
#authenticate(password : String, set_password_hash = "") : Bool
Authenticate
-
#password=(password : String) : String
Set password
-
#password_hash : String
Get password_hash
-
#password_hash=(set_password_hash : String) : String
Set password_hash
Constructor Detail
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"
Class Method Detail
def self.cost
#
Get cost
Example:
Authentication::Base.cost = 15 # => Bool(true)
Authentication::Base.cost # => 15
def self.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
Instance Method Detail
def 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"
def password=(password : String) : String
#
Set password
Example:
authentication = Authentication::Base.new
authentication.password = "test" # => "$2a$16$YXplcnR5dWlvcHFzZGZna.zN8.evmDPoNK.n.l6cx0YKKnw37jd9K"
def password_hash : String
#
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"
def 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"