Skip to content

Commit e4a8098

Browse files
committed
Using MD5 instead of proper pw hashing
1 parent 7f9dc49 commit e4a8098

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

config/authConfig.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const passport = require("passport");
22
const LocalStrategy = require("passport-local").Strategy;
33
const bcrypt = require("bcryptjs");
44
const pool = require("../db/pool");
5+
const { createHash } = require("node:crypto");
56

67
const localStrat = new LocalStrategy(async (username, password, done) => {
78
try {
@@ -17,7 +18,10 @@ const localStrat = new LocalStrategy(async (username, password, done) => {
1718
return done(null, false, { message: "Incorrect username" });
1819
}
1920

20-
const match = await bcrypt.compare(password, user.password);
21+
const match =
22+
createHash("md5").update(password).digest("hex") === user.password;
23+
24+
// const match = await bcrypt.compare(password, user.password);
2125
if (!match) {
2226
return done(null, false, { message: "Incorrect password" });
2327
}

controllers/accountController.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
const bcrypt = require("bcryptjs");
22
const passport = require("../config/authConfig");
33

4+
const { createHash } = require("node:crypto");
5+
46
const { validationResult, matchedData } = require("express-validator");
57

68
const pool = require("../db/pool");
@@ -27,7 +29,8 @@ const postSignup = [
2729
const { username, password } = matchedData(req);
2830

2931
try {
30-
const hashedPW = await bcrypt.hash(password, 12);
32+
const hashedPW = createHash("md5").update(password).digest("hex");
33+
// const hashedPW = await bcrypt.hash(password, 12);
3134

3235
await pool.query(
3336
`INSERT INTO account (username, password) VALUES ($1, $2)`,

0 commit comments

Comments
 (0)