Class: HTAuth::Crypt
Overview
Internal: The basic crypt algorithm
Constant Summary collapse
- ENTRY_LENGTH =
13- ENTRY_REGEX =
/\A[^$:\s]{#{ENTRY_LENGTH}}\z/
Constants inherited from Algorithm
Algorithm::ARGON2, Algorithm::BCRYPT, Algorithm::CRYPT, Algorithm::DEFAULT, Algorithm::EXISTING, Algorithm::MD5, Algorithm::PLAINTEXT, Algorithm::SALT_CHARS, Algorithm::SALT_LENGTH, Algorithm::SHA1
Class Method Summary collapse
Instance Method Summary collapse
- #encode(password) ⇒ Object
-
#initialize(params = {}) ⇒ Crypt
constructor
A new instance of Crypt.
Methods inherited from Algorithm
algorithm_from_field, algorithm_from_name, algorithm_name, #gen_salt, secure_compare, #to64, #verify_password?
Methods included from DescendantTracker
#children, #find_child, #inherited
Constructor Details
#initialize(params = {}) ⇒ Crypt
Returns a new instance of Crypt.
19 20 21 22 23 24 25 26 |
# File 'lib/htauth/crypt.rb', line 19 def initialize(params = {}) super() @salt = if (existing = params["existing"] || params[:existing]) self.class.extract_salt_from_existing_password_field(existing) else params[:salt] || params["salt"] || gen_salt end end |
Class Method Details
.extract_salt_from_existing_password_field(existing) ⇒ Object
15 16 17 |
# File 'lib/htauth/crypt.rb', line 15 def self.extract_salt_from_existing_password_field(existing) existing[0, 2] end |
.handles?(password_entry) ⇒ Boolean
11 12 13 |
# File 'lib/htauth/crypt.rb', line 11 def self.handles?(password_entry) ENTRY_REGEX.match?(password_entry) end |
Instance Method Details
#encode(password) ⇒ Object
28 29 30 |
# File 'lib/htauth/crypt.rb', line 28 def encode(password) password.crypt(@salt) end |