Module: Auth::Crypt

Defined in:
lib/nitro/auth/util/crypt.rb

Overview

Cryptographic utilities used by the Auth module.

Class Method Summary collapse

Class Method Details

.make_hash(value) ⇒ Object

Hashes the provided string. Returns a 40-character hex representation of the hashed value.



35
36
37
# File 'lib/nitro/auth/util/crypt.rb', line 35

def self.make_hash(value)
    Digest::SHA1.hexdigest "#{crypt_prefix}--#{value}--"
end

.make_saltObject

Create a salt for mixing with hashed strings.



40
41
42
# File 'lib/nitro/auth/util/crypt.rb', line 40

def self.make_salt
    make_hash "#{salt_prefix}-#{timestamp}"
end

.make_session_key(hashed_password) ⇒ Object

Create a session key, given a password. Use the salted/hashed password here, not the raw one!



51
52
53
# File 'lib/nitro/auth/util/crypt.rb', line 51

def self.make_session_key(hashed_password)
    make_hash hashed_password + timestamp + rand.to_s
end

.salt_password(salt, password) ⇒ Object

Mix a salt into a password and return the hashed result.



45
46
47
# File 'lib/nitro/auth/util/crypt.rb', line 45

def self.salt_password(salt, password)
    make_hash salt + password
end

.timestampObject

Creates a timestamp string for inclusion in hashed strings.



29
30
31
# File 'lib/nitro/auth/util/crypt.rb', line 29

def self.timestamp
    Time.now.strftime '%Y%m%d-%H%M%S'
end