Module: BlacklistedPassword

Defined in:
lib/blacklisted_password.rb,
lib/blacklisted_password/version.rb

Constant Summary collapse

VERSION =
"0.0.3"

Instance Method Summary collapse

Instance Method Details

#blacklist_passwordObject

This is for blacklisting password



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/blacklisted_password.rb', line 5

def blacklist_password  #This is for blacklisting password
  if password.present?
    array = YAML.load_file(BLACKLISTED_PASSWORD).split(' ')
    email_element = email_spliting(email)
    array << email_element
    array.flatten!
    password_in_downcase = password.downcase
    @value = false
    array.each do |element|
      reg_string = "#{element}"
      reg = Regexp.new(reg_string)
      result = reg.match( password_in_downcase)
      if result
        @value ||= true
        break
      else
        @value ||= false
      end
    end
    errors.add :password, "is black listed." if @value
  end
end

#email_spliting(email) ⇒ Object

This is for possible email splitting



28
29
30
31
32
33
34
# File 'lib/blacklisted_password.rb', line 28

def email_spliting(email) #This is for possible email splitting
  character_to_split = ['_','+','@','.']
  character_to_split.each do |char|
    email = email.split(char).join("^")
  end
  email.split('^')
end