Module: Passwd::Base

Included in:
Passwd
Defined in:
lib/passwd/base.rb

Instance Method Summary collapse

Instance Method Details

#auth(password_text, salt_hash, password_hash) ⇒ Object



22
23
24
25
# File 'lib/passwd/base.rb', line 22

def auth(password_text, salt_hash, password_hash)
  enc_pass = Passwd.hashing("#{salt_hash}#{password_text}")
  password_hash == enc_pass
end

#configure(options = {}, &block) ⇒ Object Also known as: config



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/passwd/base.rb', line 31

def configure(options={}, &block)
  if block_given?
    @config.configure &block
  else
    if options.empty?
      @config
    else
      @config.merge options
    end
  end
end

#create(options = {}) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/passwd/base.rb', line 13

def create(options={})
  if options.empty?
    config = @config
  else
    config = TmpConfig.new(@config, options)
  end
  Array.new(config.length){config.letters[rand(config.letters.size)]}.join
end

#hashing(plain) ⇒ Object



27
28
29
# File 'lib/passwd/base.rb', line 27

def hashing(plain)
  Digest::SHA1.hexdigest plain
end

#policy_check(password) ⇒ Object



52
53
54
# File 'lib/passwd/base.rb', line 52

def policy_check(password)
  @policy.valid?(password, @config)
end

#policy_configure(&block) ⇒ Object



44
45
46
47
48
49
50
# File 'lib/passwd/base.rb', line 44

def policy_configure(&block)
  if block_given?
    @policy.configure &block
  else
    @policy
  end
end

#reset_configObject



56
57
58
# File 'lib/passwd/base.rb', line 56

def reset_config
  @config.reset
end

#reset_policyObject



60
61
62
# File 'lib/passwd/base.rb', line 60

def reset_policy
  @policy.reset
end