wp_insert_user() function password never match

I am trying to use wp_insert_user() to add a user from the custom registration form. The user gets added to the database with a hashed password, but when the user is logged out and tries to use another custom login form to log in the password never matches. Here is the code to add the user:

$userdata = array(
    'user_login' =  $username,
    'user_email' =  $email,
    'user_pass'  =  $password,
    'first_name' =  $fname,
    'last_name'  =  $lname,
    'show_admin_bar_front' = false
);

For login:

$info = array();
$info['user_login'] = $username;
$info['user_password'] = $values['password'];
$info['remember'] = true;
$user = get_user_by( 'email', $values['email'] );
if(isset($values['email'])){
    if ( $user  wp_check_password( $values['password'], $user-data-user_pass, $user-ID ) ) {
        $exists = email_exists( $values['email'] );
        if ( $exists ) {
            $user_signon = wp_signon( $info, false );
            if ( !is_wp_error($user_signon) ){
                wp_set_current_user($user_signon-ID);
                wp_set_auth_cookie($user_signon-ID);
                wp_send_json(array(  // send JSON back
                  'loggedin' = true,
                  'message' = __('Login successful, redirecting...')
                ));
            }
        } else {
            wp_send_json(array(  // send JSON back
              'loggedin' = false,
              'message' = __('Email dont exist')
            ));
        }   
    } else {
        wp_send_json(array(  // send JSON back
          'message' = __( 'Email or password didnt match', 'diasporarestart-gd' ),
          'data'    = $values['password']
        ));
    }
}

P.S I confirm that my user exist. Wordpress just cant validate the password. Regards,

Topic password plugin-development login Wordpress

Category Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.