Class: UnixCrypt::Base
- Inherits:
-
Object
- Object
- UnixCrypt::Base
- Defined in:
- lib/unix_crypt/base.rb
Class Method Summary collapse
- .build(password, salt = nil, rounds = nil) ⇒ Object
- .generate_salt ⇒ Object
- .hash(password, salt, rounds = nil) ⇒ Object
Class Method Details
.build(password, salt = nil, rounds = nil) ⇒ Object
2 3 4 5 6 7 8 9 |
# File 'lib/unix_crypt/base.rb', line 2 def self.build(password, salt = nil, rounds = nil) salt ||= generate_salt if salt.length > max_salt_length raise UnixCrypt::SaltTooLongError, "Salts longer than #{max_salt_length} characters are not permitted" end construct_password(password, salt, rounds) end |
.generate_salt ⇒ Object
15 16 17 18 19 |
# File 'lib/unix_crypt/base.rb', line 15 def self.generate_salt # Generates a random salt using the same character set as the base64 encoding # used by the hash encoder. SecureRandom.base64((default_salt_length * 6 / 8.0).ceil).tr("+", ".")[0...default_salt_length] end |
.hash(password, salt, rounds = nil) ⇒ Object
11 12 13 |
# File 'lib/unix_crypt/base.rb', line 11 def self.hash(password, salt, rounds = nil) bit_specified_base64encode internal_hash(prepare_password(password), salt, rounds) end |