SECURITY: don't allow re-using the current password during password reset
This commit is contained in:
parent
79245a25a3
commit
7a81669c18
|
@ -340,6 +340,7 @@ en:
|
||||||
common: "is one of the 10000 most common passwords. Please use a more secure password."
|
common: "is one of the 10000 most common passwords. Please use a more secure password."
|
||||||
same_as_username: "is the same as your username. Please use a more secure password."
|
same_as_username: "is the same as your username. Please use a more secure password."
|
||||||
same_as_email: "is the same as your email. Please use a more secure password."
|
same_as_email: "is the same as your email. Please use a more secure password."
|
||||||
|
same_as_current: "is the same as your current password."
|
||||||
ip_address:
|
ip_address:
|
||||||
signup_not_allowed: "Signup is not allowed from this account."
|
signup_not_allowed: "Signup is not allowed from this account."
|
||||||
color_scheme_color:
|
color_scheme_color:
|
||||||
|
|
|
@ -14,6 +14,8 @@ class PasswordValidator < ActiveModel::EachValidator
|
||||||
record.errors.add(attribute, :same_as_username)
|
record.errors.add(attribute, :same_as_username)
|
||||||
elsif record.email.present? && value == record.email
|
elsif record.email.present? && value == record.email
|
||||||
record.errors.add(attribute, :same_as_email)
|
record.errors.add(attribute, :same_as_email)
|
||||||
|
elsif record.confirm_password?(value)
|
||||||
|
record.errors.add(attribute, :same_as_current)
|
||||||
elsif SiteSetting.block_common_passwords && CommonPasswords.common_password?(value)
|
elsif SiteSetting.block_common_passwords && CommonPasswords.common_password?(value)
|
||||||
record.errors.add(attribute, :common)
|
record.errors.add(attribute, :common)
|
||||||
end
|
end
|
||||||
|
|
|
@ -96,6 +96,15 @@ describe PasswordValidator do
|
||||||
validate
|
validate
|
||||||
expect(record.errors[:password]).to be_present
|
expect(record.errors[:password]).to be_present
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "adds an error when new password is same as current password" do
|
||||||
|
@password = "mypetsname"
|
||||||
|
record.save!
|
||||||
|
record.reload
|
||||||
|
record.password = @password
|
||||||
|
validate
|
||||||
|
expect(record.errors[:password]).to be_present
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "password not required" do
|
context "password not required" do
|
||||||
|
|
Loading…
Reference in New Issue