$creds = array(
'user_login' => 'example',
'user_password' => 'plaintextpw',
'remember' => true
);
$user = wp_signon( $creds, false );
if ( is_wp_error( $user ) ) {
$msg = $user->get_error_message();
}else{
wp_clear_auth_cookie();
wp_set_current_user ( $user->ID ); // Set the current user detail
wp_set_auth_cookie ( $user->ID ); // Set auth details in cookie
$msg = "Logged in successfully";
}