Skip to content

Latest commit

 

History

History
87 lines (74 loc) · 3.15 KB

encrypt.md

File metadata and controls

87 lines (74 loc) · 3.15 KB

npm install bcrypt var bcrypt = require('bcrypt') app.post('/submit',async (req,res)=>{ var pass = req.body.password; console.log(pass); var hashed = await bcrypt.hash(pass,10) console.log(hashed); var email = [req.body.email]; var war = email.toString(); console.log(war); Chunk.find() .then((result)=>{ for(var i=0;i<result.length;i++){ if(result[i].email===war){
console.log(result[i].email);
res.sendFile(path.join(__dirname+'/martin.html'));

        }
                    
    }
})
console.log(req.body);
<!-- update the password property in the req.body object to the hashed one -->
req.body.password=hashed;
<!-- log out the updated req.body object to confirm the modifications on it -->
console.log(req.body);
// new object    
<!-- create a new chunk called news containing the request body to be saved to the database -->
var news= new Chunk(req.body);
<!-- use  the moongoose funtion save to save the object to the database -->
news.save()
.then((result)=>{
    // res.sendFile(path.join(__dirname+'/index.html'));
    var Data = new Chunk(req.body);
    res.render('\index.ejs',{Data});
})
.catch((err)=>{
    console.log(err);
});

});

app.post('/submitt', async (req,res)=>{

var passw= req.body.password;

var em=req.body.email;

Chunk.find()

.then( async (result)=>{

console.log(result);

for (i=0;i<result.length;i++){ if(result[i].email===em){ if( await bcrypt.compare(result[i].password,passw)){ res.redirect('/home'); break; } } }

res.sendFile(path.join(__dirname+'/martin.html'));

}) .catch((err)=>{ console.log(err); })

});