public static function generate_token($user) {
        $generator = new \RandomGenerator();
        $tokenString = $generator->randomToken();
        $e = \PasswordEncryptor::create_for_algorithm('blowfish');
        $salt = $e->salt($tokenString);
        $token = sha1($e->encrypt($tokenString, $salt)) . substr(md5($user->Created.$user->LastEdited.$user->ID), 7);
        return $token;
    }