public static function hasTooManyFailedAttempts($username, $count_limit = 5, $time_limit = 1800)
    {
        $since = new DateTime();
        $since->sub(new DateInterval("PT{$time_limit}S"));

        $subquery = Yii::$app->db->createCommand()
            ->select('is_successful')
            ->from(self::tableName())
            ->where('username = :username AND performed_on > :since')
            ->order('performed_on DESC')
            ->limit($count_limit)->getText();

        return $count_limit <= (int) Yii::$app->db->createCommand()
            ->select('COUNT(NOT is_successful OR NULL)')
            ->from("({$subquery}) AS t")
            ->queryScalar([':username' => $username, ':since' => $since->format('Y-m-d H:i:s')]);
    }