public static function genCode(User $user) { $kvdb = new KVDB('auth:codes'); do { $code = sha1($user->id . ':' . self::CODE_SOLT . ':' . uniqid()); } while ($kvdb->get($code)); $kvdb->set($code, $user->id); $kvdb->expire($code, self::CODE_TTL); return $code; }
public function genHash() { $kvdb = new KVDB('users:sessions'); do { $code = sha1($this->id . ':' . self::HASH_SOLT . ':' . uniqid()); } while ($kvdb->get($code)); $kvdb->set($code, $this->id); $kvdb->expire($code, self::HASH_TTL); return $code; }