From 9ae53fcae58a22c423c9d635163df184843d86af Mon Sep 17 00:00:00 2001 From: lruzicki Date: Wed, 22 May 2024 13:50:14 +0200 Subject: [PATCH] CQI-149: password validator code refactor --- src/components/UserMasterPanel.js | 81 ++++++++++++++++--------------- 1 file changed, 41 insertions(+), 40 deletions(-) diff --git a/src/components/UserMasterPanel.js b/src/components/UserMasterPanel.js index a68467e..eda630a 100644 --- a/src/components/UserMasterPanel.js +++ b/src/components/UserMasterPanel.js @@ -27,7 +27,7 @@ import { } from "../actions"; import { passwordGenerator } from "../helpers/passwordGenerator"; -import { validatePassword } from "../helpers/passwordValidator"; // Updated import +import { validatePassword } from "../helpers/passwordValidator"; const styles = (theme) => ({ tableTitle: theme.table.title, @@ -108,6 +108,7 @@ const UserMasterPanel = (props) => { const [passwordFeedback, setPasswordFeedback] = useState(""); const [passwordScore, setPasswordScore] = useState(0); const [showPassword, setShowPassword] = useState(false); + const IS_PASSWORD_SECURED = passwordScore >= 2; const handleClickShowPassword = () => setShowPassword((show) => !show); const handleMouseDownPassword = (event) => { @@ -115,7 +116,7 @@ const UserMasterPanel = (props) => { }; const handlePasswordChange = (password) => { - const { feedback, score } = validatePassword(password, passwordPolicy, formatMessage, formatMessageWithValues); // Updated function call + const { feedback, score } = validatePassword(password, passwordPolicy, formatMessage, formatMessageWithValues); setPasswordFeedback(feedback); setPasswordScore(score); onEditedChanged({ ...edited, password }); @@ -198,47 +199,47 @@ const UserMasterPanel = (props) => { obligatoryUserFields?.email == "H" || (edited.userTypes?.includes(ENROLMENT_OFFICER_USER_TYPE) && obligatoryEOFields?.email == "H") ) && ( - - handleEmailChange(email)} - /> - - )} + + handleEmailChange(email)} + /> + + )} {!( obligatoryUserFields?.phone == "H" || (edited.userTypes?.includes(ENROLMENT_OFFICER_USER_TYPE) && obligatoryEOFields?.phone == "H") ) && ( - - onEditedChanged({ ...edited, phoneNumber })} - /> - - )} + + onEditedChanged({ ...edited, phoneNumber })} + /> + + )} { } /> - = 2 ? "primary" : "error"} className={classes.passwordFeedback}> + {passwordFeedback}