mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-05 19:20:12 +08:00
- Added `LoginAttempt` Mongoose schema to store login history - Integrated login attempt recording into login flow (success/failure) - Created `rateLimitByAccount` middleware to block login if 10 failed attempts in 10 minutes
18 lines
390 B
TypeScript
18 lines
390 B
TypeScript
import { Request, Response, NextFunction } from 'express'
|
|
import { LoginAttempt } from '../../../packages/models'
|
|
|
|
export async function recordLogin(
|
|
req: Request,
|
|
success: boolean,
|
|
message: string
|
|
) {
|
|
await LoginAttempt.create({
|
|
ip: req.ip,
|
|
userAgent: req.headers['user-agent'] || '',
|
|
success,
|
|
time: new Date(),
|
|
username: req.body.username,
|
|
message,
|
|
})
|
|
}
|