Preventing Brute Force Using Node and Express JS
问题 I'm building a website using Node and Express JS and would like to throttle invalid login attempts. Both to prevent online cracking and to reduce unnecessary database calls. What are some ways in which I can implement this? 回答1: Maybe something like this might help you get started. var failures = {}; function tryToLogin() { var f = failures[remoteIp]; if (f && Date.now() < f.nextTry) { // Throttled. Can't try yet. return res.error(); } // Otherwise do login ... } function onLoginFail() { var