Merhaba değerli hocalarım!
Şu aralar Crypto ve Mongoose Kullanarak bir backend kodlamaya çalışıyorum fakat yaşadığım bir sorundan mütevellit bir türlü Kullanıcı login olurken girilen şifreyi doğrulayamıyorum yardımcı olursanız gerçekten sevinirim.
userModals.js Kodları:
import mongoose from 'mongoose'
import crypto from 'crypto'
const userSchema = mongoose.Schema({
fullName: {
type: String,
required: true
},
username: {
type: String,
required: true
},
email: {
type: String,
required: true
},
hash: {
type: String,
required: true
},
salt: String
})
userSchema.methods.setPassword = function(password) {
this.salt = crypto.randomBytes(16).toString('hex');
this.hash = crypto.pbkdf2Sync(password, this.salt, 1000, 64, `sha512`).toString(`hex`);
};
userSchema.methods.validPassword = function(password) {
var hash = crypto.pbkdf2Sync(password, this.salt, 1000, 64, `sha512`).toString(`hex`);
return this.hash === hash;
};
const User = mongoose.model('user',userSchema)
export default User
Hatanın çıktısı ise:
