From 16f8b737f1b623af76af07b162717f562ea022ff Mon Sep 17 00:00:00 2001 From: cong meng Date: Thu, 12 May 2022 13:17:01 +1200 Subject: [PATCH] fix(pwd) EE-3161 ease the minimum password restrictions to 12 characters (#6921) * fix(pwd): EE-3161 ease the minimum password restrictions to 12 characters --- api/internal/passwordutils/strengthCheck.go | 24 +------------------ .../passwordutils/strengthCheck_test.go | 4 ++-- .../components/PasswordCheckHint.tsx | 21 ++-------------- app/portainer/helpers/password.ts | 15 +----------- app/portainer/views/init/admin/initAdmin.html | 8 +------ 5 files changed, 7 insertions(+), 65 deletions(-) diff --git a/api/internal/passwordutils/strengthCheck.go b/api/internal/passwordutils/strengthCheck.go index 99d5ca473..f6de54d9c 100644 --- a/api/internal/passwordutils/strengthCheck.go +++ b/api/internal/passwordutils/strengthCheck.go @@ -1,33 +1,11 @@ package passwordutils -import ( - "regexp" -) - const MinPasswordLen = 12 func lengthCheck(password string) bool { return len(password) >= MinPasswordLen } -func comboCheck(password string) bool { - count := 0 - regexps := [4]*regexp.Regexp{ - regexp.MustCompile(`[a-z]`), - regexp.MustCompile(`[A-Z]`), - regexp.MustCompile(`[0-9]`), - regexp.MustCompile(`[\W_]`), - } - - for _, re := range regexps { - if re.FindString(password) != "" { - count += 1 - } - } - - return count >= 3 -} - func StrengthCheck(password string) bool { - return lengthCheck(password) && comboCheck(password) + return lengthCheck(password) } diff --git a/api/internal/passwordutils/strengthCheck_test.go b/api/internal/passwordutils/strengthCheck_test.go index 1ee45461a..a84871054 100644 --- a/api/internal/passwordutils/strengthCheck_test.go +++ b/api/internal/passwordutils/strengthCheck_test.go @@ -13,9 +13,9 @@ func TestStrengthCheck(t *testing.T) { }{ {"Empty password", args{""}, false}, {"Short password", args{"portainer"}, false}, - {"Short password", args{"portaienr!@#"}, false}, + {"Short password", args{"portaienr!@#"}, true}, {"Week password", args{"12345678!@#"}, false}, - {"Week password", args{"portaienr123"}, false}, + {"Week password", args{"portaienr123"}, true}, {"Good password", args{"Portainer123"}, true}, {"Good password", args{"Portainer___"}, true}, {"Good password", args{"^portainer12"}, true}, diff --git a/app/portainer/components/PasswordCheckHint.tsx b/app/portainer/components/PasswordCheckHint.tsx index ba6ed8854..463aba0c6 100644 --- a/app/portainer/components/PasswordCheckHint.tsx +++ b/app/portainer/components/PasswordCheckHint.tsx @@ -2,17 +2,6 @@ import { react2angular } from '@/react-tools/react2angular'; import { MinPasswordLen } from '../helpers/password'; -function PasswordCombination() { - return ( - - ); -} - export function ForcePasswordUpdateHint() { return (
@@ -25,11 +14,8 @@ export function ForcePasswordUpdateHint() {

- The password must be at least {MinPasswordLen} characters long, - including a combination of one character of three of the below: + The password must be at least {MinPasswordLen} characters long.

- -
); } @@ -42,12 +28,9 @@ export function PasswordCheckHint() { {' '} - The password must be at least {MinPasswordLen} characters long, - including a combination of one character of three of the below: + The password must be at least {MinPasswordLen} characters long.

- - ); } diff --git a/app/portainer/helpers/password.ts b/app/portainer/helpers/password.ts index 86d23b17a..f2614c10e 100644 --- a/app/portainer/helpers/password.ts +++ b/app/portainer/helpers/password.ts @@ -4,19 +4,6 @@ function lengthCheck(password: string) { return password.length >= MinPasswordLen; } -function comboCheck(password: string) { - let count = 0; - const regexps = [/[a-z]/, /[A-Z]/, /[0-9]/, /[\W_]/]; - - regexps.forEach((re) => { - if (password.match(re) != null) { - count += 1; - } - }); - - return count >= 3; -} - export function StrengthCheck(password: string) { - return lengthCheck(password) && comboCheck(password); + return lengthCheck(password); } diff --git a/app/portainer/views/init/admin/initAdmin.html b/app/portainer/views/init/admin/initAdmin.html index 54408f714..bd884efe1 100644 --- a/app/portainer/views/init/admin/initAdmin.html +++ b/app/portainer/views/init/admin/initAdmin.html @@ -68,14 +68,8 @@

- The password must be at least {{ MinPasswordLen }} characters long, including a combination of one character of three of the below: + The password must be at least {{ MinPasswordLen }} characters long.

-