$loginusername = 'username';
$current_user_data = get_user_by('login',$loginusername);
$user_id = $current_user_data->ID;
// login as this user
wp_set_current_user( $user_id, $loginusername );
wp_set_auth_cookie( $user_id );
do_action( 'wp_login', $loginusername, $current_user_data );
// redirect to home page after logging in
wp_redirect( site_url() );
exit;