Skip to content

Commit 8e06bfd

Browse files
committed
Removed argon 2
1 parent dd24aa1 commit 8e06bfd

File tree

3 files changed

+99
-299
lines changed

3 files changed

+99
-299
lines changed

lib/models/user.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
const { DataTypes, Model } = require('sequelize');
22
const shortid = require("shortid")
3-
const argon2 = require("argon2");
43
const crypto = require("crypto");
54

65
const hashPassword = async function(pw){
7-
//argon2? Why? Because: https://www.youtube.com/watch?v=qQAhprPM5lw
8-
return argon2.hash(pw, {
9-
memoryCost: 2 ** 16,
10-
hashLength: 50,
11-
timeCost: 20,
12-
parallelism: 5
6+
//use scrypt to hash the password, not argon2
7+
return new Promise((resolve, reject) => {
8+
crypto.scrypt(pw, "salt", 64, (err, derivedKey) => {
9+
if(err) reject(err);
10+
resolve(derivedKey.toString('hex'));
11+
});
1312
})
1413
}
1514

@@ -83,9 +82,9 @@ class User extends Model {
8382
static async authenticate({email, password}){
8483
let user = await User.findOne({where: {email: email}});
8584
if(!user) return {success: false, error: "User doesn't exist"};
86-
//now, let's see if they gave us the right password
87-
const passwordMatch = await argon2.verify(user.hashed_password, password);
88-
85+
//now, let's see if they gave us the right password using scrypt
86+
const hashed = await hashPassword(password);
87+
const passwordMatch = hashed === user.hashed_password;
8988
if(!passwordMatch) {
9089
return {success: false, error: "Invalid credentials"};;
9190
}else{

0 commit comments

Comments
 (0)