Class: Passwd::Password

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Password

Returns a new instance of Password.



7
8
9
10
11
12
# File 'lib/passwd/password.rb', line 7

def initialize(options={})
  @text = options.fetch(:password, Passwd.create)
  @salt_text = options.fetch(:salt_text, Time.now.to_s)
  @salt_hash = Passwd.hashing(@salt_text)
  @hash = Passwd.hashing("#{@salt_hash}#{@text}")
end

Instance Attribute Details

#hashObject

Returns the value of attribute hash.



5
6
7
# File 'lib/passwd/password.rb', line 5

def hash
  @hash
end

#salt_hashObject

Returns the value of attribute salt_hash.



5
6
7
# File 'lib/passwd/password.rb', line 5

def salt_hash
  @salt_hash
end

#salt_textObject

Returns the value of attribute salt_text.



5
6
7
# File 'lib/passwd/password.rb', line 5

def salt_text
  @salt_text
end

#textObject

Returns the value of attribute text.



5
6
7
# File 'lib/passwd/password.rb', line 5

def text
  @text
end

Instance Method Details

#==(password) ⇒ Object



36
37
38
39
# File 'lib/passwd/password.rb', line 36

def ==(password)
  enc_pass = Passwd.hashing("#{@salt_hash}#{password}")
  @hash == enc_pass
end