How to set a cookie for logged in users to md5($user->ID . “my_secret”)?

Nevermind, I’ve figured it out:

            function init() {
                    $user = wp_get_current_user(); 
                    if (!$user instanceof WP_User) 
                            return; 

                    $year = time() + 60 * 60 * 24 * 30 * 12;
                    $auth = md5(join('_', array($user->ID, "my secret")));

                    setcookie('visitor_id', $user->ID, $year, "https://wordpress.stackexchange.com/");
                    setcookie('visitor_auth', $auth, $year, "https://wordpress.stackexchange.com/");
            }

            add_action('init', 'init');