# Require a Minimum Password Length

> Rejects new passwords shorter than 12 characters on the profile screen, the Add New User screen and the password reset form.

- Type: PHP
- Runs: Run everywhere
- Category: [Users](https://wpide.com/library/category/users/)
- Tags: users, password, security
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/minimum-password-length/

## Code

```php
$wpide_min_password_length = 12;

add_action( 'user_profile_update_errors', function ( $errors, $update, $user ) use ( $wpide_min_password_length ) {
    if ( ! empty( $user->user_pass ) && strlen( $user->user_pass ) < $wpide_min_password_length ) {
        $errors->add( 'pass', sprintf( '<strong>Error:</strong> Passwords must be at least %d characters long.', $wpide_min_password_length ) );
    }
}, 10, 3 );

add_action( 'validate_password_reset', function ( $errors ) use ( $wpide_min_password_length ) {
    $password = isset( $_POST['pass1'] ) && is_string( $_POST['pass1'] ) ? wp_unslash( $_POST['pass1'] ) : '';

    if ( '' !== $password && strlen( $password ) < $wpide_min_password_length ) {
        $errors->add( 'pass', sprintf( '<strong>Error:</strong> Passwords must be at least %d characters long.', $wpide_min_password_length ) );
    }
} );
```

## Notes

Change 12 to your preferred minimum. WooCommerce account forms use their own strength meter.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Require a Minimum Password Length" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
