public function validOneTimePassword($attribute, $params)
    {
        if ($this->_mode === OneTimePasswordFormBehavior::OTP_TIME) {
            $valid = $this->_authenticator->checkCode($this->_secret, $this->$attribute);
        } elseif ($this->_mode === OneTimePasswordFormBehavior::OTP_COUNTER) {
            $valid = $this->_authenticator->getCode($this->_secret, $this->getPreviousCounter()) == $this->$attribute;
        } else {
            $valid = false;
        }
        if (!$valid) {
            $this->addError($attribute, Yii::t('usr', 'Entered code is invalid.'));

            return false;
        }
        if ($this->$attribute == $this->getPreviousCode()) {
            if ($this->_mode === OneTimePasswordFormBehavior::OTP_TIME) {
                $message = Yii::t('usr', 'Please wait until next code will be generated.');
            } elseif ($this->_mode === OneTimePasswordFormBehavior::OTP_COUNTER) {
                $message = Yii::t('usr', 'Please log in again to request a new code.');
            }
            $this->addError($attribute, Yii::t('usr', 'Entered code has already been used.').' '.$message);
            $this->scenario = 'verifyOTP';

            return false;
        }

        return true;
    }