Skip to content

Commit 056593d

Browse files
committed
add encyrption of password
1 parent 17d41f2 commit 056593d

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

api/auth/auth-router.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
const bcrypt = require("bcryptjs");
12
const router = require('express').Router();
23
const {
34
checkUserAndPass,
@@ -7,7 +8,11 @@ const {
78
const Users = require("../users/user-model");
89

910
router.post('/register', checkUserAndPass, usernameNotTaken, (req, res, next) => {
10-
Users.add(req.body)
11+
let user = req.body;
12+
13+
user.password = bcrypt.hashSync(user.password, 8);
14+
15+
Users.add(user)
1116
.then( newUser => res.status(201).json(newUser))
1217
.catch(next);
1318

package-lock.json

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
},
1515
"license": "ISC",
1616
"dependencies": {
17+
"bcryptjs": "^2.4.3",
1718
"cors": "2.8.5",
1819
"express": "4.18.1",
1920
"helmet": "5.0.2",

0 commit comments

Comments
 (0)