Class: Decidim::CommonPasswords

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/decidim/common_passwords.rb

Defined Under Namespace

Classes: FileNotFoundError

Constant Summary collapse

URLS =
%w(
  https://raw.githubusercontent.com/danielmiessler/SecLists/master/Passwords/xato-net-10-million-passwords-1000000.txt
  https://raw.githubusercontent.com/danielmiessler/SecLists/master/Passwords/darkweb2017-top10000.txt
  https://raw.githubusercontent.com/danielmiessler/SecLists/master/Passwords/Common-Credentials/10-million-password-list-top-1000000.txt
).freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCommonPasswords

Returns a new instance of CommonPasswords.

Raises:



15
16
17
18
19
20
21
# File 'lib/decidim/common_passwords.rb', line 15

def initialize
  raise FileNotFoundError unless File.exist?(self.class.common_passwords_path)

  File.open(self.class.common_passwords_path, "r") do |file|
    @passwords = file.read.split
  end
end

Instance Attribute Details

#passwordsObject (readonly)

Returns the value of attribute passwords.



7
8
9
# File 'lib/decidim/common_passwords.rb', line 7

def passwords
  @passwords
end

Class Method Details

.common_password_listObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/decidim/common_passwords.rb', line 29

def self.common_password_list
  @common_password_list ||= begin
    list = []
    URLS.each do |url|
      URI.parse(url).open do |data|
        data.read.split.each do |line|
          list << line if line.length >= min_length
        end
      end
    end

    list.uniq
  end
end

.common_passwords_pathObject



50
51
52
# File 'lib/decidim/common_passwords.rb', line 50

def self.common_passwords_path
  File.join(__dir__, "db", "common-passwords.txt")
end

.min_lengthObject



44
45
46
47
48
# File 'lib/decidim/common_passwords.rb', line 44

def self.min_length
  return ::PasswordValidator::MINIMUM_LENGTH if defined?(::PasswordValidator)

  10
end

.update_passwords!Object



23
24
25
26
27
# File 'lib/decidim/common_passwords.rb', line 23

def self.update_passwords!
  File.open(common_passwords_path, "w") do |file|
    common_password_list.each { |item| file.puts(item) }
  end
end