/**
  * VJ2 登录哈希到 OpenVJ 版本登录哈希
  *
  * @param int $uid
  * @param string $password
  * @return bool
  */
 public function upgradeUserCredential($uid, $password)
 {
     $user = UserUtil::getUserObjectByUid($uid);
     if ($user === null) {
         return false;
     }
     if (!$this->user_credential->password_encoder->isOutdated($user['hash'])) {
         return false;
     }
     Application::info('credential.upgrade', ['uid' => $user['uid']]);
     return $this->user_credential->setCredential($uid, $password);
 }
Example #2
0
 /**
  * 设置用户密码
  *
  * @param int $uid
  * @param string $password
  * @return bool
  * @throws InvalidArgumentException
  */
 public function setCredential($uid, $password)
 {
     if (!Validator::int()->validate($uid)) {
         throw new InvalidArgumentException('uid', 'type_invalid');
     }
     $newHashSaltPair = $this->password_encoder->generateHash($password);
     $status = Application::coll('User')->update(['uid' => (int) $uid], ['$set' => ['hash' => $newHashSaltPair['hash'], 'salt' => $newHashSaltPair['salt']]]);
     if ($status['n'] === 1) {
         Application::info('credential.set', ['uid' => $uid]);
         return true;
     } else {
         return false;
     }
 }