mirror of
https://github.com/ToolJet/ToolJet
synced 2026-05-23 08:58:26 +00:00
Fix: restricted input of whitespaces in new password input in reset p… (#12534)
This commit is contained in:
parent
7426f2b736
commit
3a086f8182
1 changed files with 19 additions and 10 deletions
|
|
@ -88,10 +88,11 @@ function SettingsPage(props) {
|
|||
|
||||
const handlePasswordInput = (input) => {
|
||||
setNewPassword(input);
|
||||
if (input.length > 100) {
|
||||
const trimmedInput = input.trim();
|
||||
if (trimmedInput.length > 100) {
|
||||
setHelperText('Password should be Max 100 characters');
|
||||
setValidPassword(false);
|
||||
} else if (input.length < 5 && input.length > 0) {
|
||||
} else if (trimmedInput.length < 5 && trimmedInput.length > 0) {
|
||||
setHelperText('Password should be at least 5 characters');
|
||||
setValidPassword(false);
|
||||
} else {
|
||||
|
|
@ -100,11 +101,19 @@ function SettingsPage(props) {
|
|||
}
|
||||
};
|
||||
|
||||
const handleConfirmPasswordInput = (input) => {
|
||||
setConfirmPassword(input);
|
||||
};
|
||||
|
||||
const changePassword = async () => {
|
||||
const trimmedCurrentPassword = currentpassword.trim();
|
||||
const trimmedNewPassword = newPassword.trim();
|
||||
const trimmedConfirmPassword = confirmPassword.trim();
|
||||
|
||||
const errorMsg =
|
||||
(currentpassword.match(/^ *$/) !== null && 'Current password') ||
|
||||
(newPassword.match(/^ *$/) !== null && 'New password') ||
|
||||
(confirmPassword.match(/^ *$/) !== null && 'Confirm new password');
|
||||
(trimmedCurrentPassword.length === 0 && 'Current password') ||
|
||||
(trimmedNewPassword.length === 0 && 'New password') ||
|
||||
(trimmedConfirmPassword.length === 0 && 'Confirm new password');
|
||||
|
||||
if (errorMsg) {
|
||||
toast.error(errorMsg + " can't be empty!", {
|
||||
|
|
@ -112,13 +121,13 @@ function SettingsPage(props) {
|
|||
});
|
||||
return;
|
||||
}
|
||||
if (currentpassword === newPassword) {
|
||||
if (trimmedCurrentPassword === trimmedNewPassword) {
|
||||
toast.error("New password can't be the same as the current one!", {
|
||||
duration: 3000,
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (newPassword !== confirmPassword) {
|
||||
if (trimmedNewPassword !== trimmedConfirmPassword) {
|
||||
toast.error('New password and confirm new password should be same', {
|
||||
duration: 3000,
|
||||
});
|
||||
|
|
@ -127,7 +136,7 @@ function SettingsPage(props) {
|
|||
|
||||
setPasswordChangeInProgress(true);
|
||||
try {
|
||||
await userService.changePassword(currentpassword, newPassword);
|
||||
await userService.changePassword(trimmedCurrentPassword, trimmedNewPassword);
|
||||
toast.success('Password updated successfully', {
|
||||
duration: 3000,
|
||||
});
|
||||
|
|
@ -293,7 +302,7 @@ function SettingsPage(props) {
|
|||
placeholder={t('header.profileSettingPage.confirmNewPassword', 'Confirm new password')}
|
||||
value={confirmPassword}
|
||||
ref={focusRef}
|
||||
onChange={(event) => setConfirmPassword(event.target.value)}
|
||||
onChange={(event) => handleConfirmPasswordInput(event.target.value)}
|
||||
onKeyPress={confirmPasswordKeyPressHandler}
|
||||
data-cy="confirm-password-input"
|
||||
/>
|
||||
|
|
@ -301,7 +310,7 @@ function SettingsPage(props) {
|
|||
</div>
|
||||
<ButtonSolid
|
||||
isLoading={passwordChangeInProgress}
|
||||
disabled={newPassword.length < 5 || confirmPassword.length < 5 || !validPassword}
|
||||
disabled={newPassword.trim().length < 5 || confirmPassword.trim().length < 5 || !validPassword}
|
||||
onClick={changePassword}
|
||||
data-cy="change-password-button"
|
||||
>
|
||||
|
|
|
|||
Loading…
Reference in a new issue