Skip to content

Commit

Permalink
Merge pull request #381 from mehul-m-prajapati/password_validate
Browse files Browse the repository at this point in the history
Added all special chars in password validation
  • Loading branch information
Harshdev098 authored Nov 3, 2024
2 parents 5389e5a + 926c3f0 commit 37141e1
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions login-system/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,26 @@ require("dotenv").config()
const db = require('../config/mysql_connection')


// connecting database to the server
// connecting database to the server
db.getConnection((err, connection) => {
if (err) throw err;
console.log("Database Connected Successfully")
})

const validatePassword = (password) => {
const RegexPassword = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{7,}$/;
const RegexPassword = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&^#(){}[\]:;<>,.?~`+=-])[A-Za-z\d@$!%*?&^#(){}[\]:;<>,.?~`+=-]{7,}$/;
return RegexPassword.test(password)
}

const signupRateLimiter = rateLimit({
windowMs : 60*60*1000, // 1 hr
max : 10, // max 10 attempts
max : 10, // max 10 attempts
message : "Too many signup attempts , please try again after an hour."
})

const signinRateLimiter = rateLimit({
windowMs : 60*60*1000,
max : 15, // max 15 attempts
max : 15, // max 15 attempts
message : "Too many login attempts, please try again after an hour."
})

Expand All @@ -47,7 +47,7 @@ const signup=async (req, res) => {
if (err) throw (err)
const sqlSearch = "SELECT * FROM user_table WHERE email=? OR username=?";
const search_query = mysql.format(sqlSearch, [email,username])

const sqlinsert = "INSERT INTO user_table VALUES (0,?,?,?)"
const insert_query = mysql.format(sqlinsert, [username, email, hashpassword])
await connection.query(search_query, async (err, result) => {
Expand Down Expand Up @@ -83,7 +83,7 @@ const signup=async (req, res) => {
})
}

// login backend
// login backend
const signin=(req, res) => {
const email = req.body.email.trim()
const password = req.body.password.trim();
Expand Down Expand Up @@ -118,7 +118,7 @@ const signin=(req, res) => {
}

// exporting signup,signin funtion
module.exports={
signup : [signupRateLimiter,signup],
module.exports={
signup : [signupRateLimiter,signup],
signin : [signinRateLimiter,signin]
}
}

0 comments on commit 37141e1

Please sign in to comment.