Sometime we need to login to WordPress system without knowing username and password. Using these sort of functions you can bypass all authentication process and directly logged in into speficif user id.
Change $user_id value to desired user id, eg. 1 for admin.
if(!is_user_logged_in()) {
$user_id = 1;
wp_clear_auth_cookie();
wp_set_current_user( $user_id );
wp_set_auth_cookie( $user_id );
}
Place it somewhere in your theme or plugin, and, voila….. You’re logged in.

So what the heck this thing useful for?
- To login into WordPress without using username and password. You don’t say.
- To know site behavior for spesific user.
- To make connection with social networking site like Facebook or Google Plus.