Wordpress: Required Password at Register Form

By default, WordPress dont have function to allow users choose their own password when registering on your blog. For security purpose, Password will be mailed to your registration email, but sometime users dont change their password at the first time they log in to your blog; the result is they will forget it or hard to find the password in mailbox. If you want to let them choose their password, you have to write some code to add Password fields to your blog register form. Here its:

// Add Password, Repeat Password fields to WordPress registration form 
add_action( 'register_form', 'ab_add_password_fields' ); 

function ab_add_password_fields(){ ?>

<label for="password">Password  
<input class="input" id="password" name="password" size="25" tabindex="30" type="password" value=""></input></label>

<label for="repeat_password">Repeat password  
<input class="input" id="repeat_password" name="repeat_password" size="25" tabindex="40" type="password" value=""></input></label>

<?php }

// Check the form for errors
add_action( 'register_post', 'ab_check_password_fields', 10, 3);
function ab_check_password_fields($login, $email, $errors) {
if ( $_POST['password'] !== $_POST['repeat_password'] ) {
add( 'passwords_not_matched', "**ERROR**: Passwords do not match" ); 
if ( strlen( $_POST['password'] ) 

add( 'password_too_short', "**ERROR**: Passwords must be at least eight characters long" ); } } ?>

// Storing WordPress user password into database on registration

add_action( 'user_register', 'ab_store_password_fields', 100 );
function ab_store_password_fields( $user_id ){
$userdata = array();

$userdata['ID'] = $user_id;
if ( $_POST['password'] !== '' ) {
$userdata['user_pass'] = $_POST['password'];
$new_user_id = wp_update_user( $userdata );

I created a Free Plugin called Wp-Register-Password. You can download here.

Hope this help.

Written on 28 September 2012

Share your thoughts