diff --git a/app/views/users/password_reset.html.erb b/app/views/users/password_reset.html.erb index 93a5fd40c..2371150d5 100644 --- a/app/views/users/password_reset.html.erb +++ b/app/views/users/password_reset.html.erb @@ -37,7 +37,7 @@

- +

diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index df555c754..e26431ed9 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -915,6 +915,7 @@ en: reserved_usernames: "Usernames for which signup is not allowed." min_password_length: "Minimum password length." + min_admin_password_length: "Minimum password length for Admin." block_common_passwords: "Don't allow passwords that are in the 10,000 most common passwords." enable_sso: "Enable single sign on via an external site (WARNING: USERS' EMAIL ADDRESSES *MUST* BE VALIDATED BY THE EXTERNAL SITE!)" diff --git a/config/site_settings.yml b/config/site_settings.yml index a35c30b59..e868cb092 100644 --- a/config/site_settings.yml +++ b/config/site_settings.yml @@ -292,7 +292,11 @@ users: default: "admin|moderator|administrator|mod|sys|system|community|info|you|name|username|user|nickname|discourse|discourseorg|discourseforum|support" min_password_length: client: true - default: 8 + default: 10 + min: 1 + min_admin_password_length: + client: true + default: 15 min: 1 block_common_passwords: true enforce_global_nicknames: diff --git a/lib/validators/password_validator.rb b/lib/validators/password_validator.rb index 015f08f12..3eb94a095 100644 --- a/lib/validators/password_validator.rb +++ b/lib/validators/password_validator.rb @@ -6,6 +6,8 @@ class PasswordValidator < ActiveModel::EachValidator return unless record.password_required? if value.nil? record.errors.add(attribute, :blank) + elsif value.length < SiteSetting.min_admin_password_length && record.admin? + record.errors.add(attribute, :too_short, count: SiteSetting.min_admin_password_length) elsif value.length < SiteSetting.min_password_length record.errors.add(attribute, :too_short, count: SiteSetting.min_password_length) elsif record.username.present? && value == record.username diff --git a/spec/components/validators/password_validator_spec.rb b/spec/components/validators/password_validator_spec.rb index d95c0d550..3cfe4f435 100644 --- a/spec/components/validators/password_validator_spec.rb +++ b/spec/components/validators/password_validator_spec.rb @@ -40,6 +40,15 @@ describe PasswordValidator do validate expect(record.errors[:password]).to be_present end + + it "adds an error when user is admin and password is less than 15 chars" do + SiteSetting.min_admin_password_length = 15 + + @password = "12345678912" + record.admin = true + validate + expect(record.errors[:password]).to be_present + end end context "min password length is 12" do @@ -55,6 +64,7 @@ describe PasswordValidator do context "password is commonly used" do before do + SiteSetting.stubs(:min_password_length).returns(8) CommonPasswords.stubs(:common_password?).returns(true) end @@ -74,7 +84,7 @@ describe PasswordValidator do end it "adds an error when password is the same as the username" do - @password = "porkchops1" + @password = "porkchops1234" record.username = @password validate expect(record.errors[:password]).to be_present diff --git a/spec/controllers/users_controller_spec.rb b/spec/controllers/users_controller_spec.rb index eb83ce115..042cd4037 100644 --- a/spec/controllers/users_controller_spec.rb +++ b/spec/controllers/users_controller_spec.rb @@ -723,7 +723,7 @@ describe UsersController do context "with values for the fields" do let(:create_params) { { name: @user.name, - password: 'watwatwat', + password: 'watwatwatwat', username: @user.username, email: @user.email, user_fields: { @@ -773,7 +773,7 @@ describe UsersController do context "without values for the fields" do let(:create_params) { { name: @user.name, - password: 'watwatwat', + password: 'watwatwatwat', username: @user.username, email: @user.email, } } @@ -793,7 +793,7 @@ describe UsersController do let!(:staged) { Fabricate(:staged, email: "staged@account.com") } it "succeeds" do - xhr :post, :create, email: staged.email, username: "zogstrip", password: "P4ssw0rd" + xhr :post, :create, email: staged.email, username: "zogstrip", password: "P4ssw0rd$$" result = ::JSON.parse(response.body) expect(result["success"]).to eq(true) expect(User.find_by(email: staged.email).staged).to eq(false)