-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhash.js
More file actions
39 lines (29 loc) · 1.09 KB
/
Copy pathhash.js
File metadata and controls
39 lines (29 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
const bcrypt = require('bcrypt');
const {MD5} = require('crypto-js'); //import (crypto-js) to setup the token
const jwt = require('jsonwebtoken'); //import (jsonwebtoken) to setup
// bcrypt.genSalt(10,(err,salt)=>{
// if(err) return next(err);
// bcrypt.hash('password123',salt,(err,hash)=>{
// if(err) return next(err);
// console.log(hash);
// })
// })
//how to generate a token password
// const secret = 'mysecretpassword';
// const seretSalt = 'djekdjjejnnfjenn';
// const user = {
// id:1,
// token: MD5('SDFSFSDFSDF').toString() + seretSalt
// }
// const receivedToken = 'bc18c7df1f4df074829b453f0db4757ddjekdjjejnnfjenn';
// if(receivedToken === user.token){
// console.log('move forward')
// }
// console.log(user);
//How to use the (jsonwebtoken)
const id = '1000'
const secret = 'supersecret'
const receivedToken = 'eyJhbGciOiJIUzI1NiJ9.MTAwMA.L9PmEqLlZjettygguzj25agunJu6NkvVtG9RFRBnK2Y';
const token = jwt.sign(id,secret); //encode
const decodeToken = jwt.verify(receivedToken, secret) //decode to check if the token is correct
console.log(decodeToken);