Hi guys today we gonna implement password reset via email in node.js. If you user forgot there password, we send an link to you user email account....
For further actions, you may consider blocking this person and/or reporting abuse
Thank you for this amazing tutorial, After watching it carefully I noticed a small bug that you can work on later. After reseting the password, The plain password is being kept in the database. I think you should concider encrypting the password before saving to the database after reseting it
no you are wrong thats not a bug please try to see this schema we have no need to encrypt
const express =require("express")
const mongoose=require("mongoose")
const bcrypt = require('bcryptjs');
const schema=new mongoose.Schema({
firstName: {
type: String,
// required: true,
},
lastName: {
type: String,
// required: true,
},
image: {
type: String,
},
email:{
type:String,
required: true,
},
status: {
type: String,
enum: ['Pending', 'Active'],
default: 'Pending'
},
confirmationCode: {
type: String,
unique: true
},
password:{
type:String,
required: true,
},
phone:{
type:String,
// required: true,
},
createdAt: {
type: Date,
default: Date.now,
},
phoneOtp:String
},
{ timestamps: true }
)
schema.pre('save', async function(next) {
try {
// check method of registration
const user = this;
if (!user.isModified('password')) next();
// generate salt
const salt = await bcrypt.genSalt(10);
// hash the password
const hashedPassword = await bcrypt.hash(this.password, salt);
// replace plain text password with hashed password
this.password = hashedPassword;
next();
} catch (error) {
return next(error);
}
});
schema.methods.matchPassword = async function (password) {
console.log(password)
try {
return await bcrypt.compare(password, this.password);
} catch (error) {
throw new Error(error);
}
};
const mens=new mongoose.model("APJ_Ecomusers",schema)
module.exports=mens
Getting this error message:
Error: connect ECONNREFUSED 127.0.0.1:587
at TCPConnectWrap.afterConnect as oncomplete {
errno: -4078,
code: 'ESOCKET',
syscall: 'connect',
address: '127.0.0.1',
port: 587,
command: 'CONN'
} email not sent
How to solve this error.
@cyberwolves can u show the solution for this error
@stylespriley if u got the solution please share. Facing the same issue here
Awesome Article I am new to this Web Development. Just by reading this i was able to understand the flow. Thank You. Keep writing such articles.
Thank you, subscribe to my Youtube channel youtube.com/channel/UCxyo2h1uAuMT1...
Thanks, i did something similar to this using react,postgres and express.js
Can you provide the music name that you used in your video.
nice share gan
iam from indonesia
Arigato gozaimasu.. senpai
thanks mate, works fine!
Thank you so much your blogs are amazing
UnhandledPromiseRejectionWarning: CastError: Cast to ObjectId failed for value "undefined" (type string) at path "_id" for model "User"
please help me
Nice
This is really helpful. Thanks.
This doesn't work emails getting blocked!
did you solve this issue?
Can you please explain the .env variables?
HOST = // email host
USER = // email id
PASS = // email password
SERVICE = // email service
BASE_URL = "localhost:8080/api"
did you ever figure this out?
in the postman while posting ,
localhost:8080/api/password-reset/...
Here whats the token i have to enter