Class: Keybox::PasswordHash

Inherits:
Object
  • Object
show all
Defined in:
lib/keybox/password_hash.rb

Overview

this is an implementation of the password hash algorithm used at www.xs4all.nl/~jlpoutre/BoT/Javascript/PasswordComposer/

This implementation uses the SHA1 hash instead of the MD5

This class uses a master password and with that information generates a unique password for all subsequent strings passed to it.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(master_password = "") ⇒ PasswordHash

Returns a new instance of PasswordHash.



18
19
20
21
# File 'lib/keybox/password_hash.rb', line 18

def initialize(master_password = "")
    @master_password = master_password
    @digest_class    = ::Digest::SHA1
end

Instance Attribute Details

#master_password=(value) ⇒ Object (writeonly)

Sets the attribute master_password

Parameters:

  • value

    the value to set the attribute master_password to.



16
17
18
# File 'lib/keybox/password_hash.rb', line 16

def master_password=(value)
  @master_password = value
end

Instance Method Details

#password_for(str) ⇒ Object



28
29
30
# File 'lib/keybox/password_hash.rb', line 28

def password_for(str)
    @digest_class.hexdigest("#{@master_password}:#{str}")[0..8]
end

#password_for_url(url) ⇒ Object



23
24
25
26
# File 'lib/keybox/password_hash.rb', line 23

def password_for_url(url)
    uri = URI.parse(url)
    password_for(uri.host)
end