Class: UnixCrypt::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/unix_crypt.rb

Direct Known Subclasses

MD5, SHABase

Class Method Summary collapse

Class Method Details

.build(password, salt = nil, rounds = nil) ⇒ Object



16
17
18
19
20
# File 'lib/unix_crypt.rb', line 16

def self.build(password, salt = nil, rounds = nil)
  salt ||= generate_salt

  "$#{identifier}$#{salt}$#{hash(password, salt, rounds)}"
end

.generate_saltObject



22
23
24
25
26
# File 'lib/unix_crypt.rb', line 22

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).gsub("=", "").tr("+", ".")
end