From 9c1a4a94edc6c3a5a5e1cc8edb2cf3e7d448c726 Mon Sep 17 00:00:00 2001 From: Akash Deep Date: Sat, 7 Dec 2024 23:31:09 +0530 Subject: [PATCH 1/2] Update Readme.md #5 Added all contributors. --- Readme.md | 1 + 1 file changed, 1 insertion(+) diff --git a/Readme.md b/Readme.md index 151e1dd..067c070 100644 --- a/Readme.md +++ b/Readme.md @@ -211,6 +211,7 @@ We'd like to acknowledge the efforts and contributions of the following individu - **[Akash Deep](https://github.com/akashdeep023)** - Full Stack development and Project lead. - **[Ekant Verma](https://github.com/ekantverma)** - Full Stack development. - **[Anjali Kumari](https://github.com/Anjali17aj)** - Full Stack development. +- **[Shanedra Singh](https://github.com/shanedraSingh/)** - Full Stack development. ## **License** From 0975609fdc8c9d4ba709dd08eea3511c68bf154a Mon Sep 17 00:00:00 2001 From: Silent-Watcher Date: Sun, 8 Dec 2024 09:50:22 +0330 Subject: [PATCH 2/2] feat:Add password requirements in Register controller --- backend/controllers/auth.js | 6 ++++ backend/package-lock.json | 50 +++++++++++++++++++++++++++ backend/package.json | 1 + backend/routes/auth.js | 3 +- backend/validation/auth.validation.js | 8 +++++ 5 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 backend/validation/auth.validation.js diff --git a/backend/controllers/auth.js b/backend/controllers/auth.js index c3b5637..56d1da6 100644 --- a/backend/controllers/auth.js +++ b/backend/controllers/auth.js @@ -8,6 +8,12 @@ const registerUser = async (req, res, next) => { if (existingUser) { return res.status(400).json({ message: `User Already Exist` }); } + + const validationResult = registerSchema.validate({password}); + if (validationResult.error){ + return res.status(400).json({ message: `Error: Password must be 8+ chars, with upper, lower, number, and special (@$!%*?&#)` }); + } + password = bcrypt.hashSync(password, 8); const userData = new User({ name, diff --git a/backend/package-lock.json b/backend/package-lock.json index 6c006df..6854608 100644 --- a/backend/package-lock.json +++ b/backend/package-lock.json @@ -13,6 +13,7 @@ "cors": "^2.8.5", "dotenv": "^16.4.5", "express": "^4.19.2", + "joi": "^17.13.3", "jsonwebtoken": "^9.0.2", "mongoose": "^8.4.1" }, @@ -20,6 +21,21 @@ "node": "18.17.1" } }, + "node_modules/@hapi/hoek": { + "version": "9.3.0", + "resolved": "https://registry.npmjs.org/@hapi/hoek/-/hoek-9.3.0.tgz", + "integrity": "sha512-/c6rf4UJlmHlC9b5BaNvzAcFv7HZ2QHaV0D4/HNlBdvFnvQq8RI4kYdhyPCl7Xj+oWvTWQ8ujhqS53LIgAe6KQ==", + "license": "BSD-3-Clause" + }, + "node_modules/@hapi/topo": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/@hapi/topo/-/topo-5.1.0.tgz", + "integrity": "sha512-foQZKJig7Ob0BMAYBfcJk8d77QtOe7Wo4ox7ff1lQYoNNAb6jwcY1ncdoy2e9wQZzvNy7ODZCYJkK8kzmcAnAg==", + "license": "BSD-3-Clause", + "dependencies": { + "@hapi/hoek": "^9.0.0" + } + }, "node_modules/@mongodb-js/saslprep": { "version": "1.1.7", "resolved": "https://registry.npmjs.org/@mongodb-js/saslprep/-/saslprep-1.1.7.tgz", @@ -28,6 +44,27 @@ "sparse-bitfield": "^3.0.3" } }, + "node_modules/@sideway/address": { + "version": "4.1.5", + "resolved": "https://registry.npmjs.org/@sideway/address/-/address-4.1.5.tgz", + "integrity": "sha512-IqO/DUQHUkPeixNQ8n0JA6102hT9CmaljNTPmQ1u8MEhBo/R4Q8eKLN/vGZxuebwOroDB4cbpjheD4+/sKFK4Q==", + "license": "BSD-3-Clause", + "dependencies": { + "@hapi/hoek": "^9.0.0" + } + }, + "node_modules/@sideway/formula": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/@sideway/formula/-/formula-3.0.1.tgz", + "integrity": "sha512-/poHZJJVjx3L+zVD6g9KgHfYnb443oi7wLu/XKojDviHy6HOEOA6z1Trk5aR1dGcmPenJEgb2sK2I80LeS3MIg==", + "license": "BSD-3-Clause" + }, + "node_modules/@sideway/pinpoint": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/@sideway/pinpoint/-/pinpoint-2.0.0.tgz", + "integrity": "sha512-RNiOoTPkptFtSVzQevY/yWtZwf/RxyVnPy/OcA9HBM3MlGDnBEYL5B41H0MTn0Uec8Hi+2qUtTfG2WWZBmMejQ==", + "license": "BSD-3-Clause" + }, "node_modules/@types/webidl-conversions": { "version": "7.0.3", "resolved": "https://registry.npmjs.org/@types/webidl-conversions/-/webidl-conversions-7.0.3.tgz", @@ -468,6 +505,19 @@ "node": ">= 0.10" } }, + "node_modules/joi": { + "version": "17.13.3", + "resolved": "https://registry.npmjs.org/joi/-/joi-17.13.3.tgz", + "integrity": "sha512-otDA4ldcIx+ZXsKHWmp0YizCweVRZG96J10b0FevjfuncLO1oX59THoAmHkNubYJ+9gWsYsp5k8v4ib6oDv1fA==", + "license": "BSD-3-Clause", + "dependencies": { + "@hapi/hoek": "^9.3.0", + "@hapi/topo": "^5.1.0", + "@sideway/address": "^4.1.5", + "@sideway/formula": "^3.0.1", + "@sideway/pinpoint": "^2.0.0" + } + }, "node_modules/jsonwebtoken": { "version": "9.0.2", "resolved": "https://registry.npmjs.org/jsonwebtoken/-/jsonwebtoken-9.0.2.tgz", diff --git a/backend/package.json b/backend/package.json index 399265a..31e58a7 100644 --- a/backend/package.json +++ b/backend/package.json @@ -18,6 +18,7 @@ "cors": "^2.8.5", "dotenv": "^16.4.5", "express": "^4.19.2", + "joi": "^17.13.3", "jsonwebtoken": "^9.0.2", "mongoose": "^8.4.1" } diff --git a/backend/routes/auth.js b/backend/routes/auth.js index 1c57ec3..d0c9fd8 100644 --- a/backend/routes/auth.js +++ b/backend/routes/auth.js @@ -2,8 +2,9 @@ const express = require("express"); const router = express.Router(); const authControllers = require("../controllers/auth"); const wrapAsync = require("../middlewares/wrapAsync"); +const { registerSchema } = require("../validation/auth.validation"); -router.post("/register", wrapAsync(authControllers.registerUser)); +router.post("/register" ,wrapAsync(authControllers.registerUser)); router.post("/login", wrapAsync(authControllers.loginUser)); module.exports = router; diff --git a/backend/validation/auth.validation.js b/backend/validation/auth.validation.js new file mode 100644 index 0000000..1949274 --- /dev/null +++ b/backend/validation/auth.validation.js @@ -0,0 +1,8 @@ +const Joi = require('joi'); + +const registerSchema = Joi.object({ + password: Joi.string() + .pattern(new RegExp('/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&#])[A-Za-z\d@$!%*?&#]{8,}$/gm')), +}) + +module.exports = {registerSchema} \ No newline at end of file