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.
-
#email_addresses ⇒ Array<EmailAddress>
The email addresses which use the password.
-
#id ⇒ Integer
The primary key of the password.
-
#notes ⇒ Array<Note>
The associated notes.
-
#plain_text ⇒ String
The clear-text of the password.
-
#service_credentials ⇒ Array<ServiceCredential>
The service credentials that use the password.
-
#user_names ⇒ Array<UserName>
The user names which use the password.
-
#web_credentials ⇒ Array<WebCredential>
Any web credentials that use the password.
Class Method Summary collapse
-
.for_user(name) ⇒ Array<Password>
Searches for all passwords used by a specific user.
-
.import(password) ⇒ Password
Parses a password.
-
.lookup(password) ⇒ Password?
Looks up the password.
-
.with_email_address(email) ⇒ Array<Password>
Searches all passwords that are associated with an email address.
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 |
#email_addresses ⇒ Array<EmailAddress>
The email addresses which use the password.
68 |
# File 'lib/ronin/db/password.rb', line 68 has_many :email_addresses, through: :credentials |
#id ⇒ Integer
The primary key of the password.
41 |
# File 'lib/ronin/db/password.rb', line 41 attribute :id, :integer |
#notes ⇒ Array<Note>
The associated notes.
92 |
# File 'lib/ronin/db/password.rb', line 92 has_many :notes, dependent: :destroy |
#plain_text ⇒ String
The clear-text of the password.
47 |
# File 'lib/ronin/db/password.rb', line 47 attribute :plain_text, :string |
#service_credentials ⇒ Array<ServiceCredential>
The service credentials that use the password.
76 |
# File 'lib/ronin/db/password.rb', line 76 has_many :service_credentials, through: :credentials |
#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 |
#web_credentials ⇒ Array<WebCredential>
Any web credentials that use the password.
84 |
# File 'lib/ronin/db/password.rb', line 84 has_many :web_credentials, through: :credentials |
Class Method Details
.for_user(name) ⇒ Array<Password>
Searches for all passwords used by a specific user.
107 108 109 |
# File 'lib/ronin/db/password.rb', line 107 def self.for_user(name) joins(credentials: :user_name).where(credentials: {ronin_user_names: {name: name}}) end |
.import(password) ⇒ Password
Parses a password.
170 171 172 |
# File 'lib/ronin/db/password.rb', line 170 def self.import(password) create(plain_text: password.to_s) end |
.lookup(password) ⇒ Password?
Looks up the password.
155 156 157 |
# File 'lib/ronin/db/password.rb', line 155 def self.lookup(password) find_by(plain_text: password.to_s) end |
.with_email_address(email) ⇒ Array<Password>
Searches all passwords that are associated with an email address.
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/ronin/db/password.rb', line 127 def self.with_email_address(email) unless email.include?('@') raise(ArgumentError,"invalid email address #{email.inspect}") end user, domain = email.split('@',2) return joins(credentials: {email_address: [:user_name, :host_name]}).where( credentials: { email_address: { ronin_user_names: {name: user}, ronin_host_names: {name: domain} } } ) end |
Instance Method Details
#count ⇒ Integer
The number of credentials which use this password.
229 230 231 |
# File 'lib/ronin/db/password.rb', line 229 def count self.credentials.count end |
#digest(algorithm, prepend_salt: nil, append_salt: nil) ⇒ String
Hashes the password.
206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
# File 'lib/ronin/db/password.rb', line 206 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.
241 242 243 |
# File 'lib/ronin/db/password.rb', line 241 def to_s self.plain_text end |