Class: Ronin::Password

Inherits:
Object
  • Object
show all
Includes:
Model
Defined in:
lib/ronin/password.rb

Overview

Represents a password that can be stored in the Database.

Instance Method Summary collapse

Methods included from Model

included

Instance Method Details

#countInteger

The number of credentials which use this password.

Returns:

  • (Integer)

    The number of credentials that use the password.

Since:

  • 1.0.0



116
117
118
# File 'lib/ronin/password.rb', line 116

def count
  self.credentials.count
end

#digest(algorithm, options = {}) ⇒ String

Hashes the password.

Examples:

pass = Password.new(:clear_text => 'secret')

pass.digest(:sha1)
# => "e5e9fa1ba31ecd1ae84f75caaa474f3a663f05f4"

pass.digest(:sha1, :prepend_salt => "A\x90\x00")
# => "e2817656a48c49f24839ccf9295b389d8f985904"

pass.digest(:sha1, :append_salt => "BBBB")
# => "aa6ca21e446d425fc044bbb26e950a788444a5b8"

Parameters:

  • digest (Symbol, String)

    The digest algorithm to use.

  • options (Hash) (defaults to: {})

    Additional options.

Options Hash (options):

  • :prepend_salt (String)

    The salt data to prepend to the password.

  • :append_salt (String)

    The salt data to append to the password.

Returns:

  • (String)

    The hex-digest of the hashed password.

Raises:

  • (ArgumentError)

    Unknown Digest algorithm.

Since:

  • 1.0.0



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/ronin/password.rb', line 84

def digest(algorithm,options={})
  digest_class = begin
                   Digest.const_get(algorithm.to_s.upcase)
                 rescue LoadError
                   raise(ArgumentError,"Unknown Digest algorithm #{algorithm}")
                 end

  hash = digest_class.new

  if options[:prepend_salt]
    hash << options[:prepend_salt].to_s
  end

  hash << self.clear_text

  if options[:append_salt]
    hash << options[:append_salt].to_s
  end

  return hash.hexdigest
end

#inspectString

Inspects the password.

Returns:

  • (String)

    The inspected password.

Since:

  • 1.0.0



144
145
146
# File 'lib/ronin/password.rb', line 144

def inspect
  "#<#{self.class}: #{self.clear_text}>"
end

#to_sString

Converts the password into a String.

Returns:

  • (String)

    The clear-text of the password.

Since:

  • 1.0.0



130
131
132
# File 'lib/ronin/password.rb', line 130

def to_s
  self.clear_text
end