Class: ADAM6050::Password

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

Overview

Usage

The following example creates a password and uses it to validate an encoded string.

password = Password.new 'b6TSkfr6'

password == 'b6TSkfr6' # => false
password == "]\tklTYM\t" # => true

The next example creates a password that will match any string.

password = Password.new

password == 'anything' # => true

Defined Under Namespace

Classes: FormatError

Instance Method Summary collapse

Constructor Details

#initialize(plain = nil) ⇒ Password

Returns a new instance of Password.

Parameters:

  • plain (String) (defaults to: nil)

    the plain text version of the password.

Raises:

  • (FormatError)

    if the plain text password is longer than 8 characters.



32
33
34
35
36
37
38
39
40
41
# File 'lib/adam6050/password.rb', line 32

def initialize(plain = nil)
  if plain
    password = obfuscate plain
    define_singleton_method(:==) { |text| password == text }
  else
    define_singleton_method(:==) { |_| true }
  end

  freeze
end