Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Password validation feature #6

Open
wants to merge 2 commits into
base: 3-add-password-requirements-in-register-page
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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**

Expand Down
6 changes: 6 additions & 0 deletions backend/controllers/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -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});
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Require registerSchema
const { registerSchema } = require("../validation/auth.validation");

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,
Expand Down
50 changes: 50 additions & 0 deletions backend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
3 changes: 2 additions & 1 deletion backend/routes/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove all changes.


router.post("/register", wrapAsync(authControllers.registerUser));
router.post("/register" ,wrapAsync(authControllers.registerUser));
router.post("/login", wrapAsync(authControllers.loginUser));

module.exports = router;
8 changes: 8 additions & 0 deletions backend/validation/auth.validation.js
Original file line number Diff line number Diff line change
@@ -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}