Generate authentication cookie contents.

Signature

wp_generate_auth_cookie( $user_id, $expiration, $scheme = 'auth', $token = '' )
user_id
 (int) User ID
expiration
 (int) Cookie expiration in seconds
scheme
 (string) Optional. The cookie scheme to use: auth, secure_auth, or logged_in
Default: 'auth'
token
 (string) User's session token to use for this cookie
Default: ''

Return

(string) Authentication cookie contents. Empty string if user does not exist.

Source

function wp_generate_auth_cookie( $user_id, $expiration, $scheme = 'auth', $token = '' ) {
	$user = get_userdata($user_id);
	if ( ! $user ) {
		return '';
	}

	if ( ! $token ) {
		$manager = WP_Session_Tokens::get_instance( $user_id );
		$token = $manager->create( $expiration );
	}

	$pass_frag = substr($user->user_pass, 8, 4);

	$key = wp_hash( $user->user_login . '|' . $pass_frag . '|' . $expiration . '|' . $token, $scheme );
	$hash = hash_hmac( 'sha256', $user->user_login . '|' . $expiration . '|' . $token, $key );

	$cookie = $user->user_login . '|' . $expiration . '|' . $token . '|' . $hash;

	/**
	 * Filter the authentication cookie.
11 more lines...
WP Trac GitHub

Link here