Closed ozten closed 11 years ago
I didn't consider this, as it cannot handle expiring a range of attempts.
Example: 5:20 - I do a bad pin attempt 4 times 5:29 - I do a bad pin attempt 5:32 - I make a bad pin attempt
As I interpreted the requirements, at 5:32 we should still count the attempts made at 5:29 against the user, but expire the first 4 attempts from 5:20.
@ozten You're right, based on the requirements as they are written, your solution is better. I'd like to suggest that we relax the "5 attempts per 10 min" requirement a bit if it helps make the code simpler/faster.
This requirement takes advantage of the fact that after 10 minutes of coming into existence, a PIN will expire. Any previous attempts at cracking that PIN are irrelevant after 10 minutes given that the PIN no longer exists.
So in your example, when the 5:32 attempt comes in, we could assume that the 5:29 attempt was for a previous PIN and is no longer relevant. Now technically speaking, the PIN expiry and the blacklist may not overlap perfectly, for example:
but that only doubles the number of attempts in the worst case, it doesn't significantly change the strength of the solution. We would still satisfy a "10 attempts per 10 min" requirement.
I'd like to suggest that we relax the "5 attempts per 10 min" requirement a bit if it helps make the code simpler/faster.
Okay, I'll update the code as you've requested.
@fmarier thanks again for all your help.
@lloyd - did you have any other feedback, that would block this PR? or the overall PIN fix?
This is ready to review. I've removed the list of expiration dates and replaced it with a single date.
Thanks!
@fmarier does this new commit address all open concerns?
belatedly, I'm completely happy with this if @ozten and @fmarier are!
r+ from me
I've reviewed the change and as far as I can tell, it does everything that was proposed in #234.
With respect to simplifying the memory management, have you thought of storing only the first timestamp as well as a counter?
e.g.
{ 'foo@example.com': [ 19826484210, 3 ] }
where 19826484210 is the timestamp and 3 is the number of failed attemptsThat would make
_expireCounter
a constant time function and would also limit the size of each map entry to a fixed size of 2 numbers.