File tree Expand file tree Collapse file tree 2 files changed +8
-4
lines changed Expand file tree Collapse file tree 2 files changed +8
-4
lines changed Original file line number Diff line number Diff line change @@ -28,7 +28,8 @@ const config = {
2828 } ,
2929 authAttempts : {
3030 forIp : 50 ,
31- forIpAndUser : 7
31+ forIpAndUser : 7 ,
32+ durationOfBlocking : 24
3233 } ,
3334 jwt : {
3435 secret : {
Original file line number Diff line number Diff line change @@ -20,11 +20,14 @@ class AuthAttempt extends MongoModels {
2020 Assert . ok ( ip , 'Missing ip argument.' ) ;
2121 Assert . ok ( username , 'Missing username argument.' ) ;
2222
23+ const config = Config . get ( '/authAttempts' ) ;
24+ const duration = new Date ( Date . now ( ) - config . durationOfBlocking * 60 * 60 * 1000 ) ;
25+
2326 const [ countByIp , countByIpAndUser ] = await Promise . all ( [
24- this . count ( { ip } ) ,
25- this . count ( { ip, username } )
27+ this . count ( { ip, timeCreated : { $gt : duration } } ) ,
28+ this . count ( { ip, username, timeCreated : { $gt : duration } } )
2629 ] ) ;
27- const config = Config . get ( '/authAttempts' ) ;
30+
2831 const ipLimitReached = countByIp >= config . forIp ;
2932 const ipUserLimitReached = countByIpAndUser >= config . forIpAndUser ;
3033
You can’t perform that action at this time.
0 commit comments