minor changes
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
const { body } = require('express-validator');
|
||||
const { validationResult, body } = require('express-validator');
|
||||
|
||||
const locationValidation = [
|
||||
body('name').trim().isLength({ min: 1 }).withMessage('Name must not be empty').escape(),
|
||||
@ -69,7 +69,34 @@ const createValidation = [
|
||||
body('jobTitle').trim().isLength({ min: 1 }).withMessage('Job title must not be empty').escape(),
|
||||
];
|
||||
|
||||
|
||||
function isStrongPassword(password) {
|
||||
// Password must be at least 10 characters long
|
||||
if (password.length < 10) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Password must contain at least one uppercase letter
|
||||
if (!/[A-Z]/.test(password)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Password must contain at least one lowercase letter
|
||||
if (!/[a-z]/.test(password)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Password must contain at least one digit
|
||||
if (!/\d/.test(password)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Password must contain at least one symbol
|
||||
if (!/[!@#$%^&*(),.?":{}|<>]/.test(password)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
module.exports = {
|
||||
locationValidation,locationValidationUpdate,locationdeleteValidation
|
||||
,sensorValidation,sensorupdateValidation,sensordeleteValidation,loginValidation,otpValidation
|
||||
|
@ -7,10 +7,10 @@ const crypto = require("crypto");
|
||||
const validator = require('validator');
|
||||
const axios = require('axios');
|
||||
|
||||
const {validationResult } = require('express-validator');
|
||||
const {locationValidation, locationValidationUpdate, locationdeleteValidation
|
||||
const { validationResult } = require('express-validator');
|
||||
const { locationValidation, locationValidationUpdate, locationdeleteValidation
|
||||
,sensorValidation, sensorupdateValidation, sensordeleteValidation, loginValidation
|
||||
,otpValidation, createValidation} = require('./modules/validationMiddleware');
|
||||
,otpValidation, createValidation } = require('./modules/validationMiddleware');
|
||||
const rateLimit = require('./modules/rateLimitMiddleware');
|
||||
const { generateOTP, sendOTPByEmail } = require('./modules/otpUtils');
|
||||
const { format } = require('date-fns');
|
||||
@ -255,15 +255,15 @@ function isStrongPassword(password) {
|
||||
return true;
|
||||
}
|
||||
|
||||
app.post(
|
||||
'/createUser', createValidation, async (req, res) => {
|
||||
app.post
|
||||
('/createUser', createValidation,
|
||||
async (req, res) => {
|
||||
try {
|
||||
const errors = validationResult(req);
|
||||
const errors = validationResult(req);
|
||||
|
||||
if (!errors.isEmpty()) {
|
||||
return res.status(400).json({ errors: errors.array() });
|
||||
}
|
||||
|
||||
const sessionTokencookie = req.cookies['sessionToken'];
|
||||
|
||||
// Verify sessionToken with the one stored in the database
|
||||
@ -286,10 +286,6 @@ app.post(
|
||||
// Extract the username of the user creating a new user
|
||||
const creatorUsername = req.session.username; // Adjust this based on how you store the creator's username in your session
|
||||
|
||||
// Additional password complexity check
|
||||
if (!isStrongPassword(password)) {
|
||||
return res.status(400).json({ error: "Password does not meet complexity requirements" });
|
||||
}
|
||||
|
||||
// Check if the username is already taken
|
||||
const existingUser = await User.findOne({ where: { username } });
|
||||
|
@ -57,7 +57,7 @@
|
||||
<a class="nav-link link text-black display-4" href="index.html#contacts02-9">Contacts</a>
|
||||
</li>
|
||||
</ul>
|
||||
<div class="navbar-buttons mbr-section-btn"><a class="btn btn-primary display-4" href="https://mobiri.se">Login</a></div>
|
||||
<div class="navbar-buttons mbr-section-btn"><a class="btn btn-primary display-4" href="http://localhost:3000/login">Login</a></div>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
|
Reference in New Issue
Block a user