password encrpytion before entering database: pre("save") function
hassan2bit.bearblog.dev·1d
Preview
Report Post

Hassan2bit

Home Blogs contact portfolio

  • 08 Dec, 2025 *

a simple documentation on hashing password before saving into db

  • A user schema model has been defined, using mongoose, it looks something like this:
const userSchema = new mongoose.Schema({
email: {
type: String,
required: true,
unique: true,
minlength: 4,
lowercase: true,
},
username: {
type: String,
required: true,
unique: true,
minlength: 4,
trim: true,
},
password: {
type: String,
required: true,
minlength: 6,
},

createdAt: {
type: Date,
default: Date.now,
},

role: {
default: "student",
enum: ["student", "admin"],
type: String...

Similar Posts

Loading similar posts...