Implement user registration and email verification features

This commit is contained in:
Isuru Bimsara
2026-08-17 16:52:44 +05:30
parent ef8db0988b
commit c3d9f899a1
11 changed files with 781 additions and 53 deletions
+28
View File
@@ -0,0 +1,28 @@
//app/utils/emailVerification.util.js
const crypto = require("crypto");
/**
* Generate a cryptographically secure
* random email-verification token.
*/
const generateEmailVerificationToken = () => {
return crypto.randomBytes(32).toString("hex");
};
/**
* Hash verification token before
* storing it in database.
*/
const hashEmailVerificationToken = (token) => {
return crypto
.createHash("sha256")
.update(token)
.digest("hex");
};
module.exports = {
generateEmailVerificationToken,
hashEmailVerificationToken,
};
@@ -0,0 +1,21 @@
const validateEmail = (email) => {
// Must be a string
if (typeof email !== "string") {
return false;
}
// Remove spaces
const trimmedEmail = email.trim();
// Basic email format validation
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
return emailRegex.test(trimmedEmail);
};
const normalizeEmail = (email) => {
return email.trim().toLowerCase();
};
module.exports = {
validateEmail, normalizeEmail
};
@@ -1,3 +1,4 @@
//app/utils/validation/validatePassword.util.js
const validatePassword = (password) => {
// Check if password is a string
if (typeof password !== "string") {