# Let New Users Choose Their Password When Registering

> Adds password and confirm-password fields to the WordPress registration form, so new members pick their own password instead of waiting for a "set your password" email.

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

## Code

```php
// Minimum password length.
$wpide_reg_min_length = 10;
// Log the new member in right after registering.
$wpide_reg_auto_login = false;

add_action( 'register_form', function () use ( $wpide_reg_min_length ) {
    ?>
    <p>
        <label for="wpide_pass1">Password</label>
        <input type="password" name="wpide_pass1" id="wpide_pass1" class="input" autocomplete="new-password" minlength="<?php echo (int) $wpide_reg_min_length; ?>" required>
    </p>
    <p>
        <label for="wpide_pass2">Confirm password</label>
        <input type="password" name="wpide_pass2" id="wpide_pass2" class="input" autocomplete="new-password" required>
    </p>
    <?php
} );

add_filter( 'registration_errors', function ( $errors ) use ( $wpide_reg_min_length ) {
    if ( ! isset( $_POST['wpide_pass1'] ) ) {
        return $errors;
    }

    $pass1 = (string) wp_unslash( $_POST['wpide_pass1'] );
    $pass2 = isset( $_POST['wpide_pass2'] ) ? (string) wp_unslash( $_POST['wpide_pass2'] ) : '';

    if ( strlen( $pass1 ) < $wpide_reg_min_length ) {
        $errors->add( 'wpide_pass_short', sprintf( '<strong>Error:</strong> Your password must be at least %d characters long.', $wpide_reg_min_length ) );
    } elseif ( $pass1 !== $pass2 ) {
        $errors->add( 'wpide_pass_mismatch', '<strong>Error:</strong> The two passwords do not match.' );
    }

    return $errors;
} );

// register_new_user fires once the account exists and errors have passed.
add_action( 'register_new_user', function ( $user_id ) use ( $wpide_reg_auto_login ) {
    if ( empty( $_POST['wpide_pass1'] ) ) {
        return;
    }

    wp_set_password( (string) wp_unslash( $_POST['wpide_pass1'] ), $user_id );

    // They know their password, so only tell the admin about the new account.
    remove_action( 'register_new_user', 'wp_send_new_user_notifications' );
    wp_new_user_notification( $user_id, null, 'admin' );

    if ( $wpide_reg_auto_login ) {
        wp_set_current_user( $user_id );
        wp_set_auth_cookie( $user_id );
    }
}, 5 );

add_filter( 'registration_redirect', function ( $redirect ) use ( $wpide_reg_auto_login ) {
    if ( empty( $_POST['wpide_pass1'] ) ) {
        return $redirect;
    }

    return $wpide_reg_auto_login ? home_url( '/' ) : add_query_arg( 'wpide_registered', 1, wp_login_url() );
} );

add_filter( 'login_message', function ( $message ) {
    if ( isset( $_GET['wpide_registered'] ) ) {
        $message .= '<p class="message">Registration complete. You can log in with your new password now.</p>';
    }

    return $message;
} );
```

## Notes

Set $wpide_reg_auto_login to true to log new members in straight away. Only the wp-login.php registration form is changed.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Let New Users Choose Their Password When Registering" 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/
