Block passwords that are in the top 5000 most common passwords. Site setting block_common_passwords can disable this feature.

This commit is contained in:
Neil Lalonde
2013-12-20 16:34:34 -05:00
parent b4f547b3e2
commit ab12695d63
11 changed files with 10204 additions and 35 deletions

View File

@@ -1,3 +1,5 @@
require_dependency "common_passwords/common_passwords"
class PasswordValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
@@ -6,6 +8,8 @@ class PasswordValidator < ActiveModel::EachValidator
record.errors.add(attribute, :blank)
elsif value.length < SiteSetting.min_password_length
record.errors.add(attribute, :too_short, count: SiteSetting.min_password_length)
elsif SiteSetting.block_common_passwords && CommonPasswords.common_password?(value)
record.errors.add(attribute, :common)
end
end