mirror of
https://github.com/casdoor/casdoor.git
synced 2025-07-16 06:33:50 +08:00
ci: add password complexity options to organization edit page (#1949)
* Support uploading roles and permissions via xlsx file. * Template xlsx file for uploading users and permissions. * reformat according to gofumpt. * fix typo. * add password complexity options to organization edit page. * add password complexity options to organization edit page. * Fixed Typos. * Fixed Typos. * feat:add password complexity options to organization edit page * Auto generate i18n fields. * Refactor code according to instructions * Support autocheck passwd complexity in frontend when setting passwd in user edit page. * feat:Backend Support for password validation in signup and forget page. * feat:Frontend Support for password validation in signup and forget page. * Add default password complex option & Update historical empty filed with default option. * Migrator for field `password_complex_options` in org table. * feat: support frontend password complex option check in user_edit/forget/signup page. * frontend update for user edit page * update i18n file --------- Co-authored-by: hsluoyz <hsluoyz@qq.com>
This commit is contained in:
82
web/src/common/PasswordChecker.js
Normal file
82
web/src/common/PasswordChecker.js
Normal file
@ -0,0 +1,82 @@
|
||||
// Copyright 2023 The Casdoor Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
import i18next from "i18next";
|
||||
|
||||
function isValidOption_AtLeast6(password) {
|
||||
if (password.length < 6) {
|
||||
return i18next.t("user:The password must have at least 6 characters");
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
function isValidOption_AtLeast8(password) {
|
||||
if (password.length < 8) {
|
||||
return i18next.t("user:The password must have at least 8 characters");
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
function isValidOption_Aa123(password) {
|
||||
const regex = /^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9]).+$/;
|
||||
if (!regex.test(password)) {
|
||||
return i18next.t("user:The password must contain at least one uppercase letter, one lowercase letter and one digit");
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
function isValidOption_SpecialChar(password) {
|
||||
const regex = /^(?=.*[!@#$%^&*]).+$/;
|
||||
if (!regex.test(password)) {
|
||||
return i18next.t("user:The password must contain at least one special character");
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
function isValidOption_NoRepeat(password) {
|
||||
const regex = /(.)\1+/;
|
||||
if (regex.test(password)) {
|
||||
return i18next.t("user:The password must not contain any repeated characters");
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
export function checkPasswordComplexity(password, options) {
|
||||
if (password.length === 0) {
|
||||
return i18next.t("login:Please input your password!");
|
||||
}
|
||||
|
||||
if (options.length === 0) {
|
||||
options = ["AtLeast6"];
|
||||
}
|
||||
|
||||
const checkers = {
|
||||
AtLeast6: isValidOption_AtLeast6,
|
||||
AtLeast8: isValidOption_AtLeast8,
|
||||
Aa123: isValidOption_Aa123,
|
||||
SpecialChar: isValidOption_SpecialChar,
|
||||
NoRepeat: isValidOption_NoRepeat,
|
||||
};
|
||||
|
||||
for (const option of options) {
|
||||
const checkerFunc = checkers[option];
|
||||
if (checkerFunc) {
|
||||
const errorMsg = checkerFunc(password);
|
||||
if (errorMsg !== "") {
|
||||
return errorMsg;
|
||||
}
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
Reference in New Issue
Block a user