From 42ee0e0ce6ffeee1393dd319921edbce68527236 Mon Sep 17 00:00:00 2001 From: rishabh7923 Date: Fri, 25 Oct 2024 04:33:40 +0530 Subject: [PATCH] Added Validation At Register Page --- server/routes/admin.js | 11 +++++ views/admin/register.ejs | 93 +++++++++++++++++++++++++++++++++++++--- 2 files changed, 98 insertions(+), 6 deletions(-) diff --git a/server/routes/admin.js b/server/routes/admin.js index eeccf33..b7e454c 100644 --- a/server/routes/admin.js +++ b/server/routes/admin.js @@ -222,8 +222,19 @@ router.post('/register', async (req, res) => { return res.redirect('/register'); // Change to '/register' } + if (!/^[a-zA-Z0-9]+$/.test(username) || username.length < 3) { + req.flash('error', 'Username must be at least 3 characters long and contain only alphanumeric characters.'); + return res.redirect('/register'); + } + + if (password.length < 8 || !/\d/.test(password) || !/[!@#$%^&*]/.test(password)) { + req.flash('error', 'Password must be at least 8 characters long, contain a number, and a special character.'); + return res.redirect('/register'); + } + try { const existingUser = await User.findOne({ username }); + if (existingUser) { req.flash('error', 'Username already taken'); return res.redirect('/register'); // Change to '/register' diff --git a/views/admin/register.ejs b/views/admin/register.ejs index b299110..d5ac374 100644 --- a/views/admin/register.ejs +++ b/views/admin/register.ejs @@ -1,11 +1,92 @@

Register

-
- - + +
+
+ + + + +
+ +
+ + + + +
+ +
+ +
+
- - -
+ + + + \ No newline at end of file