/**
* Create, store, and return a token for long-term authentication
*
* @param int $userId
* @return string (to store in a cookie, for example)
*/
public function createAuthToken(int $userId) : string
{
$f = $this->tableConfig['fields']['longterm'];
$selector = \random_bytes(self::SELECTOR_BYTES);
$validator = \random_bytes(self::VALIDATOR_BYTES);
$this->db->insert($this->tableConfig['table']['longterm'], [$f['userid'] => $userId, $f['selector'] => Base64::encode($selector), $f['validator'] => CryptoUtil::hash($validator)]);
return Base64::encode($selector . $validator);
}