Class: Ronin::DB::Password
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Ronin::DB::Password
- Includes:
- Model, Model::Importable
- Defined in:
- lib/ronin/db/password.rb
Overview
Instance Attribute Summary collapse
-
#credentials ⇒ Array<Credential>
The credentials which use the password.
-
#id ⇒ Integer
The primary key of the password.
-
#plain_text ⇒ String
The clear-text of the password.
-
#user_names ⇒ Array<UserName>
The user names which use the password.
Class Method Summary collapse
-
.import(password) ⇒ Password
Parses a password.
-
.lookup(password) ⇒ Password?
Looks up the password.
Instance Method Summary collapse
-
#count ⇒ Integer
The number of credentials which use this password.
-
#digest(algorithm, prepend_salt: nil, append_salt: nil) ⇒ String
Hashes the password.
-
#to_s ⇒ String
Converts the password into a String.
Methods included from Model::Importable
Methods included from Model
Instance Attribute Details
#credentials ⇒ Array<Credential>
The credentials which use the password.
54 |
# File 'lib/ronin/db/password.rb', line 54 has_many :credentials, dependent: :destroy |
#id ⇒ Integer
The primary key of the password.
41 |
# File 'lib/ronin/db/password.rb', line 41 attribute :id, :integer |
#plain_text ⇒ String
The clear-text of the password.
47 |
# File 'lib/ronin/db/password.rb', line 47 attribute :plain_text, :string |
#user_names ⇒ Array<UserName>
The user names which use the password.
60 |
# File 'lib/ronin/db/password.rb', line 60 has_many :user_names, through: :credentials |
Class Method Details
.import(password) ⇒ Password
Parses a password.
88 89 90 |
# File 'lib/ronin/db/password.rb', line 88 def self.import(password) create(plain_text: password.to_s) end |
.lookup(password) ⇒ Password?
Looks up the password.
73 74 75 |
# File 'lib/ronin/db/password.rb', line 73 def self.lookup(password) find_by(plain_text: password.to_s) end |
Instance Method Details
#count ⇒ Integer
The number of credentials which use this password.
147 148 149 |
# File 'lib/ronin/db/password.rb', line 147 def count self.credentials.count end |
#digest(algorithm, prepend_salt: nil, append_salt: nil) ⇒ String
Hashes the password.
124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/ronin/db/password.rb', line 124 def digest(algorithm, prepend_salt: nil, append_salt: nil) digest_class = begin Digest.const_get(algorithm.upcase) rescue LoadError raise(ArgumentError,"Unknown Digest algorithm #{algorithm}") end hash = digest_class.new hash << prepend_salt.to_s if prepend_salt hash << self.plain_text hash << append_salt.to_s if append_salt return hash.hexdigest end |
#to_s ⇒ String
Converts the password into a String.
159 160 161 |
# File 'lib/ronin/db/password.rb', line 159 def to_s self.plain_text end |