- fixed password length validation;

- added settings for the password min/max length;
This commit is contained in:
Nikita Sinelnikov
2021-09-21 13:25:49 +03:00
parent 5394305340
commit e8c1497ec4
7 changed files with 45 additions and 11 deletions
@@ -676,6 +676,12 @@ if ( ! class_exists( 'um\admin\core\Admin_Settings' ) ) {
'reset_require_strongpass' => array(
'sanitize' => 'bool',
),
'password_min_chars' => array(
'sanitize' => 'absint',
),
'password_max_chars' => array(
'sanitize' => 'absint',
),
'profile_noindex' => array(
'sanitize' => 'bool',
),
@@ -1048,6 +1054,20 @@ if ( ! class_exists( 'um\admin\core\Admin_Settings' ) ) {
'label' => __( 'Require a strong password? (when user resets password only)', 'ultimate-member' ),
'tooltip' => __( 'Enable or disable a strong password rules on password reset and change procedure', 'ultimate-member' ),
),
array(
'id' => 'password_min_chars',
'type' => 'number',
'label' => __( 'Password minimum length', 'ultimate-member' ),
'tooltip' => __( 'If you want to enable a minimum number of characters to be in password. User password field in the UM forms has own settings for that. Leave empty to use default value 8', 'ultimate-member' ),
'size' => 'small',
),
array(
'id' => 'password_max_chars',
'type' => 'number',
'label' => __( 'Password maximum length', 'ultimate-member' ),
'tooltip' => __( 'If you want to enable a maximum number of characters to be in password. User password field in the UM forms has own settings for that. Leave empty to use default value 30', 'ultimate-member' ),
'size' => 'small',
),
array(
'id' => 'profile_noindex',
'type' => 'select',
+2
View File
@@ -523,6 +523,8 @@ if ( ! class_exists( 'um\Config' ) ) {
'use_um_gravatar_default_builtin_image' => 'default',
'use_um_gravatar_default_image' => 0,
'reset_require_strongpass' => 0,
'password_min_chars' => 8,
'password_max_chars' => 30,
'account_tab_password' => 1,
'account_tab_privacy' => 1,
'account_tab_notifications' => 1,
+7 -2
View File
@@ -543,11 +543,16 @@ if ( ! class_exists( 'um\core\Password' ) ) {
if ( UM()->options()->get( 'reset_require_strongpass' ) ) {
if ( strlen( utf8_decode( $args['user_password'] ) ) < 8 ) {
$min_length = UM()->options()->get( 'password_min_chars' );
$min_length = ! empty( $min_length ) ? $min_length : 8;
$max_length = UM()->options()->get( 'password_max_chars' );
$max_length = ! empty( $max_length ) ? $max_length : 30;
if ( mb_strlen( $args['user_password'] ) < $min_length ) {
UM()->form()->add_error( 'user_password', __( 'Your password must contain at least 8 characters', 'ultimate-member' ) );
}
if ( strlen( utf8_decode( $args['user_password'] ) ) > 30 ) {
if ( mb_strlen( $args['user_password'] ) > $max_length ) {
UM()->form()->add_error( 'user_password', __( 'Your password must contain less than 30 characters', 'ultimate-member' ) );
}
+7 -2
View File
@@ -82,11 +82,16 @@ function um_submit_account_errors_hook( $args ) {
}
if ( UM()->options()->get( 'account_require_strongpass' ) ) {
if ( strlen( utf8_decode( $args['user_password'] ) ) < 8 ) {
$min_length = UM()->options()->get( 'password_min_chars' );
$min_length = ! empty( $min_length ) ? $min_length : 8;
$max_length = UM()->options()->get( 'password_max_chars' );
$max_length = ! empty( $max_length ) ? $max_length : 30;
if ( mb_strlen( $args['user_password'] ) < $min_length ) {
UM()->form()->add_error( 'user_password', __( 'Your password must contain at least 8 characters', 'ultimate-member' ) );
}
if ( strlen( utf8_decode( $args['user_password'] ) ) > 30 ) {
if ( mb_strlen( $args['user_password'] ) > $max_length ) {
UM()->form()->add_error( 'user_password', __( 'Your password must contain less than 30 characters', 'ultimate-member' ) );
}
+4 -4
View File
@@ -595,7 +595,7 @@ function um_submit_form_errors_hook_( $args ) {
}
if ( isset( $array['min_chars'] ) && $array['min_chars'] > 0 ) {
if ( $args[ $key ] && strlen( utf8_decode( $args[ $key ] ) ) < $array['min_chars'] ) {
if ( $args[ $key ] && mb_strlen( $args[ $key ] ) < $array['min_chars'] ) {
if ( empty( $array['label'] ) ) {
UM()->form()->add_error( $key, sprintf( __( 'This field must contain at least %s characters', 'ultimate-member' ), $array['min_chars'] ) );
} else {
@@ -605,7 +605,7 @@ function um_submit_form_errors_hook_( $args ) {
}
if ( isset( $array['max_chars'] ) && $array['max_chars'] > 0 ) {
if ( $args[ $key ] && strlen( utf8_decode( $args[ $key ] ) ) > $array['max_chars'] ) {
if ( $args[ $key ] && mb_strlen( $args[ $key ] ) > $array['max_chars'] ) {
if ( empty( $array['label'] ) ) {
UM()->form()->add_error( $key, sprintf( __( 'This field must contain less than %s characters', 'ultimate-member' ), $array['max_chars'] ) );
} else {
@@ -895,7 +895,7 @@ function um_submit_form_errors_hook_( $args ) {
$profile_show_bio = UM()->options()->get( 'profile_show_bio' );
if ( $profile_show_bio ) {
if ( strlen( utf8_decode( str_replace( array( "\r\n", "\n", "\r\t", "\t" ), ' ', $args['description'] ) ) ) > $max_chars && $max_chars ) {
if ( mb_strlen( str_replace( array( "\r\n", "\n", "\r\t", "\t" ), ' ', $args['description'] ) ) > $max_chars && $max_chars ) {
UM()->form()->add_error( 'description', sprintf( __( 'Your user description must contain less than %s characters', 'ultimate-member' ), $max_chars ) );
}
}
@@ -921,4 +921,4 @@ function um_invalid_nonce_redirect_url( $url ) {
return $url;
}
add_filter( 'um_login_invalid_nonce_redirect_url', 'um_invalid_nonce_redirect_url', 10, 1 );
add_filter( 'um_register_invalid_nonce_redirect_url', 'um_invalid_nonce_redirect_url', 10, 1 );
add_filter( 'um_register_invalid_nonce_redirect_url', 'um_invalid_nonce_redirect_url', 10, 1 );
+2 -2
View File
@@ -66,7 +66,7 @@ function um_dynamic_user_profile_title( $title, $id = '' ) {
return $title;
}
return ( strlen( $title ) !== strlen( utf8_decode( $title ) ) ) ? $title : utf8_encode( $title );
return ( strlen( $title ) !== mb_strlen( $title ) ) ? $title : utf8_encode( $title );
}
add_filter( 'the_title', 'um_dynamic_user_profile_title', 100000, 2 );
@@ -158,4 +158,4 @@ function um_change_profile_photo_label( $fields ) {
}
return $fields;
}
add_filter( 'um_predefined_fields_hook', 'um_change_profile_photo_label', 10, 1 );
add_filter( 'um_predefined_fields_hook', 'um_change_profile_photo_label', 10, 1 );
+3 -1
View File
@@ -155,11 +155,12 @@ The plugin works with popular caching plugins by automatically excluding Ultimat
* To learn more about version 2.1 please see this [docs](https://docs.ultimatemember.com/article/1512-upgrade-2-1-0)
* UM2.1+ is a significant update to the Member Directories' code base from 2.0.x. Please make sure you take a full-site backup with restore point before updating the plugin
= 2.2.5: September 21, 2021 =
= 2.2.5: September 22, 2021 =
* Enhancements:
- Added: Ability to insert SoundCloud track URL instead of Track ID
- Added: Settings for the password min/max length (Ultimate Member > Settings > Users)
* Bugfixes:
@@ -168,6 +169,7 @@ The plugin works with popular caching plugins by automatically excluding Ultimat
- Fixed: Restriction settings fields conditions on wp-admin screens
- Fixed: Account `user_login` field validation removed as redundant. The field is disabled and not used in code flow
- Fixed: `display_name` data update after First + Last name fields edition on the Account page
- Fixed: Password length validation on the Account page and Password Reset page
= 2.2.4: August 27, 2021 =