Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions helper/bcrypt.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const bcrypt = require('bcrypt');
const saltRounds = 10;
function compare(plaintxt,hash){
return bcrypt.compare(plaintxt, hash).then(function(result) {
if(result){
return true;
}
else{
return false;
}
});
}
function hash(plaintxt)
{
return bcrypt.hash(plaintxt, saltRounds).then(function(hash) {
if(hash)
{
return hash;
}
else{
return;
}


});
}
module.exports.Hash=hash;
module.exports.Compare=compare
30 changes: 30 additions & 0 deletions middleware/auth.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const User = require("../models/users.model");
module.exports={
checkusername:async function(req,res,next){
const username=req.body.username;
const user= await User.findOne({username:username});
if(user != null)
{
return res.status(422).json({Status:false,errorName:"username"})

}


next();

},
checkemail:async function(req,res,next)
{
const email=req.body.email;
const checkEmail=await User.findOne({email:email});
if(checkEmail != null)
{

return res.status(422).json({Status:false,errorName:"email"})

}

next();

}
}
4 changes: 2 additions & 2 deletions middleware.js → middleware/middleware.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
const jwt = require("jsonwebtoken");
const config = require("./config");
const config = require("../config");

let checkToken = (req, res, next) => {
let token = req.headers["authorization"];
console.log(token);
token = token.slice(7, token.length);
if (token) {
jwt.verify(token, config.key, (err, decoded) => {
Expand All @@ -25,6 +24,7 @@ let checkToken = (req, res, next) => {
}
};


module.exports = {
checkToken: checkToken,
};
Loading