Skip to content

Commit

Permalink
feature #12: Compare supplied password with hashed.
Browse files Browse the repository at this point in the history
  • Loading branch information
Boosmith committed Aug 29, 2019
1 parent f6b2d2b commit 3a2fba5
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/tools/apiServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const server = jsonServer.create();
const path = require("path");
const fs = require("fs");
const jwt = require("jsonwebtoken");
const bcrypt = require("bcrypt");
const router = jsonServer.router(path.join(__dirname, "db.json"));
const users = JSON.parse(
fs.readFileSync(path.join(__dirname, "db.json"), "UTF-8")
Expand Down Expand Up @@ -86,7 +87,9 @@ function verifyToken(token) {
function isAuthenticated(userName, password) {
return (
users.findIndex(
user => user.userName === userName && user.password === password
user =>
user.userName === userName &&
bcrypt.compareSync(password, user.password)
) !== -1
);
}

0 comments on commit 3a2fba5

Please sign in to comment.