Skip to content
Snippets Groups Projects
Commit 5ab2f3db authored by Andrei Cioromila's avatar Andrei Cioromila
Browse files

feat(user-manager): add password strength validation for each applicable route

parent e4872bcc
No related branches found
No related tags found
3 merge requests!196S25 - EiC submit revision,!189S25,!183Hin 961 strong password
const { services } = require('pubsweet-component-helper-service')
const { token } = require('pubsweet-server/src/authentication')
const { passwordStrengthRegex } = require('config')
module.exports = models => async (req, res) => {
const { password, newPassword } = req.body
if (!services.checkForUndefinedParams(password, newPassword))
return res.status(400).json({ error: 'Missing required params.' })
if (newPassword.length < 7)
return res
.status(400)
.json({ error: 'Password needs to be at least 7 characters long.' })
if (!passwordStrengthRegex.test(newPassword))
return res.status(400).json({
error: 'Password is too weak. Please check password requirements.',
})
let user
try {
......
const { pick } = require('lodash')
const Chance = require('chance')
const { passwordStrengthRegex } = require('config')
const chance = new Chance()
......@@ -15,6 +16,10 @@ module.exports = models => async (req, res) => {
error: 'Terms & Conditions must be read and approved.',
})
}
if (!passwordStrengthRegex.test(req.body.password))
return res.status(400).json({
error: 'Password is too weak. Please check password requirements.',
})
req.body = pick(req.body, [
'email',
'title',
......
const { services } = require('pubsweet-component-helper-service')
const { passwordStrengthRegex } = require('config')
module.exports = models => async (req, res) => {
const { email, password, token } = req.body
if (!services.checkForUndefinedParams(email, password, token))
return res.status(400).json({ error: 'missing required params' })
if (password.length < 7)
return res
.status(400)
.json({ error: 'password needs to be at least 7 characters long' })
if (!passwordStrengthRegex.test(req.body.password))
return res.status(400).json({
error: 'Password is too weak. Please check password requirements.',
})
const validateResponse = await services.validateEmailAndToken({
email,
......
......@@ -142,4 +142,7 @@ module.exports = {
editor: 'editorRecommendation',
},
},
passwordStrengthRegex: new RegExp(
'^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[!@#$%^&*])(?=.{6,128})',
),
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment