diff options
| author | Jan Tuomi <jan.tuomi@eficode.com> | 2020-02-05 19:50:40 +0200 |
|---|---|---|
| committer | Jan Tuomi <jan.tuomi@eficode.com> | 2020-02-05 19:50:40 +0200 |
| commit | f9b88d03e322734b3e81e2df6e1dd2d13c919d6b (patch) | |
| tree | ed22518b1565717cfc710f00307a17898c2e3849 /backend/src/authn.js | |
| parent | 71d9490d0988c97b8b023a70e0b61c65f32ad3b9 (diff) | |
Implement password strength requirements
Diffstat (limited to 'backend/src/authn.js')
| -rw-r--r-- | backend/src/authn.js | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/backend/src/authn.js b/backend/src/authn.js index c6c4a2e..40c7da8 100644 --- a/backend/src/authn.js +++ b/backend/src/authn.js @@ -2,6 +2,7 @@ const base64 = require('base-64'); const sha512 = require('js-sha512'); const shortid = require('shortid'); const db = require('./db'); +const owaspPw = require('owasp-password-strength-test'); const buildSessionCookie = ({ username, sessionToken, isLogout }) => { if (!isLogout) { @@ -78,6 +79,15 @@ const registerRoute = async (req, res) => { }); } + const owaspPwTestResults = owaspPw.test(password); + if (!owaspPwTestResults.strong) { + res.status(400); + return res.json({ + error: 'Password not strong enough', + errors: owaspPwTestResults.errors, + }); + } + const salt = shortid.generate(); const pwHash = sha512(salt + password); |
