@experium/nest-bruteforce-guard
Version:
Authorization protection from bruteforce
68 lines (67 loc) • 2.8 kB
JavaScript
;
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var _a;
Object.defineProperty(exports, "__esModule", { value: true });
exports.LoginAttempt = void 0;
const typeorm_1 = require("typeorm");
const mongodb_1 = require("mongodb");
let LoginAttempt = class LoginAttempt {
constructor(login, ip, loginFailure = false, attemptBlocked = false, userDisabled = false, badPassword = false) {
this.login = login;
this.ip = ip;
this.date = new Date();
this.loginFailure = loginFailure;
this.attemptBlocked = attemptBlocked;
this.userDisabled = userDisabled;
this.badPassword = badPassword;
}
};
__decorate([
typeorm_1.ObjectIdColumn(),
__metadata("design:type", typeof (_a = typeof mongodb_1.ObjectID !== "undefined" && mongodb_1.ObjectID) === "function" ? _a : Object)
], LoginAttempt.prototype, "id", void 0);
__decorate([
typeorm_1.Column(),
__metadata("design:type", String)
], LoginAttempt.prototype, "login", void 0);
__decorate([
typeorm_1.Column(),
__metadata("design:type", String)
], LoginAttempt.prototype, "ip", void 0);
__decorate([
typeorm_1.Column(),
typeorm_1.Index({ expireAfterSeconds: 31536000 }) // 1 year
,
__metadata("design:type", Date)
], LoginAttempt.prototype, "date", void 0);
__decorate([
typeorm_1.Column(),
__metadata("design:type", Boolean)
], LoginAttempt.prototype, "loginFailure", void 0);
__decorate([
typeorm_1.Column(),
__metadata("design:type", Boolean)
], LoginAttempt.prototype, "attemptBlocked", void 0);
__decorate([
typeorm_1.Column(),
__metadata("design:type", Boolean)
], LoginAttempt.prototype, "userDisabled", void 0);
__decorate([
typeorm_1.Column(),
__metadata("design:type", Boolean)
], LoginAttempt.prototype, "badPassword", void 0);
LoginAttempt = __decorate([
typeorm_1.Entity(),
typeorm_1.Index(['login', 'date']),
typeorm_1.Index(['ip', 'date']),
__metadata("design:paramtypes", [String, String, Boolean, Boolean, Boolean, Boolean])
], LoginAttempt);
exports.LoginAttempt = LoginAttempt;