Skip to content

Commit cb3729b

Browse files
author
Tsvetoslav Lazarov
committed
Missed the encryption for the user model
1 parent 7787d1c commit cb3729b

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"@angular/router": "3.2.3",
2323
"body-parser": "^1.15.2",
2424
"core-js": "^2.4.1",
25+
"crypto": "0.0.3",
2526
"express": "^4.14.0",
2627
"express-session": "^1.14.2",
2728
"mongoose": "^4.7.4",

server/models/user-model.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const mongoose = require("mongoose");
22
const mongooseSchema = mongoose.Schema;
3+
const encryption = require("../utils/encryption");
34

45
const userSchema = mongooseSchema({
56
username: { type: String, required: true, unique: true },

server/utils/encryption.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const crypto = require("crypto");
2+
3+
function generateSalt() {
4+
return crypto.randomBytes(128).toString("base64");
5+
}
6+
7+
function generateHashedPassword(salt, password) {
8+
return crypto.createHmac("sha256", salt)
9+
.update(password)
10+
.digest("hex");
11+
}
12+
13+
module.exports = {
14+
generateSalt,
15+
generateHashedPassword
16+
};

0 commit comments

Comments
 (0)