fix unique char counting in password validator

This commit is contained in:
Neil Lalonde
2017-02-10 10:38:17 -05:00
parent 137e941814
commit 94e1105af7
3 changed files with 8 additions and 8 deletions

View File

@ -18,7 +18,7 @@ class PasswordValidator < ActiveModel::EachValidator
record.errors.add(attribute, :same_as_current)
elsif SiteSetting.block_common_passwords && CommonPasswords.common_password?(value)
record.errors.add(attribute, :common)
elsif value.chars.uniq.size < SiteSetting.password_unique_characters
elsif value.chars.inject(Hash.new(0)) { |h,char| h[char] += 1; h }.reject { |k,v| v > 1 }.size < SiteSetting.password_unique_characters
record.errors.add(attribute, :unique_characters)
end
end