@@ -206,19 +206,76 @@ function checkAllProxies() {
206206 }
207207}
208208
209- // Checks if new password and confirm password match
210- function checkPasswordMatch ( ) {
209+ // Validates password length (minimum 8 characters)
210+ function validatePasswordLength ( ) {
211211 var newPassword = document . getElementById ( "new_password" ) . value ;
212212 var confirmPassword = document . getElementById ( "confirm_password" ) . value ;
213- if ( newPassword == confirmPassword ) {
214- if ( newPassword . length > 0 ) {
215- replaceElement ( "error_password" , "success_password" ) ;
216- return true ;
213+
214+ // Check if either password field is not empty and has less than 8 characters
215+ if ( ( newPassword . length > 0 && newPassword . length < 8 ) ||
216+ ( confirmPassword . length > 0 && confirmPassword . length < 8 ) ) {
217+ showElement ( "error_password_length" ) ;
218+ hideElement ( "error_password" ) ;
219+ hideElement ( "success_password" ) ;
220+ return false ;
221+ } else {
222+ hideElement ( "error_password_length" ) ;
223+ // Only validate match if both fields have valid length
224+ if ( newPassword . length >= 8 && confirmPassword . length >= 8 ) {
225+ return validatePasswordMatch ( ) ;
217226 }
227+ return true ;
228+ }
229+ }
230+
231+ // Checks if new password and confirm password match (internal function)
232+ function validatePasswordMatch ( ) {
233+ var newPassword = document . getElementById ( "new_password" ) . value ;
234+ var confirmPassword = document . getElementById ( "confirm_password" ) . value ;
235+
236+ if ( newPassword == confirmPassword ) {
237+ hideElement ( "error_password" ) ;
238+ hideElement ( "error_password_length" ) ;
239+ showElement ( "success_password" ) ;
240+ return true ;
218241 } else {
219- replaceElement ( "success_password" , "error_password" ) ;
242+ hideElement ( "success_password" ) ;
243+ hideElement ( "error_password_length" ) ;
244+ showElement ( "error_password" ) ;
245+ return false ;
246+ }
247+ }
248+
249+ // Checks if new password and confirm password match (main function for compatibility)
250+ function checkPasswordMatch ( ) {
251+ var newPassword = document . getElementById ( "new_password" ) . value ;
252+ var confirmPassword = document . getElementById ( "confirm_password" ) . value ;
253+
254+ // Check length first
255+ if ( ( newPassword . length > 0 && newPassword . length < 8 ) ||
256+ ( confirmPassword . length > 0 && confirmPassword . length < 8 ) ) {
257+ showElement ( "error_password_length" ) ;
258+ hideElement ( "error_password" ) ;
259+ hideElement ( "success_password" ) ;
260+ return false ;
261+ }
262+
263+ // Hide length error if length is valid
264+ hideElement ( "error_password_length" ) ;
265+
266+ // Check match if both passwords have content
267+ if ( newPassword . length > 0 && confirmPassword . length > 0 ) {
268+ return validatePasswordMatch ( ) ;
269+ }
270+
271+ // If passwords are empty, hide all messages
272+ if ( newPassword . length === 0 && confirmPassword . length === 0 ) {
273+ hideElement ( "error_password" ) ;
274+ hideElement ( "error_password_length" ) ;
275+ hideElement ( "success_password" ) ;
220276 }
221- return false ;
277+
278+ return newPassword . length >= 8 && confirmPassword . length >= 8 ;
222279}
223280
224281// Opens the update password form
@@ -232,6 +289,7 @@ function cancelPasswordUpdate() {
232289 hideElement ( "password_update" ) ;
233290 hideElement ( "success_password" ) ;
234291 hideElement ( "error_password" ) ;
292+ hideElement ( "error_password_length" ) ;
235293 replaceElement ( "cancel_password_update" , "open_password_update" ) ;
236294 document . getElementById ( "new_password" ) . value = "" ;
237295 document . getElementById ( "confirm_password" ) . value = "" ;
@@ -240,9 +298,10 @@ function cancelPasswordUpdate() {
240298// Enables the save button if the password is correct
241299function enableSaveButton ( ) {
242300 var pass_length = document . getElementById ( "password" ) . value . length ;
243- // var isPasswordUpdateClosed = document.getElementById("password_update").hidden;
244- var isPasswordUpdateClosed = document . getElementById ( "password_update" ) . classList . contains ( "hidden" )
245- if ( ( checkPasswordMatch ( ) || isPasswordUpdateClosed ) && pass_length > 0 ) {
301+ var isPasswordUpdateClosed = document . getElementById ( "password_update" ) . classList . contains ( "hidden" ) ;
302+ var isPasswordValid = isPasswordUpdateClosed || checkPasswordMatch ( ) ;
303+
304+ if ( isPasswordValid && pass_length > 0 ) {
246305 replaceElement ( 'save_label_dummy' , 'save_label' ) ;
247306 } else {
248307 replaceElement ( 'save_label' , 'save_label_dummy' ) ;
0 commit comments