|
1 | 1 | const { DataTypes, Model } = require('sequelize'); |
2 | 2 | const shortid = require("shortid") |
3 | | -const argon2 = require("argon2"); |
4 | 3 | const crypto = require("crypto"); |
5 | 4 |
|
6 | 5 | 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 | + }); |
13 | 12 | }) |
14 | 13 | } |
15 | 14 |
|
@@ -83,9 +82,9 @@ class User extends Model { |
83 | 82 | static async authenticate({email, password}){ |
84 | 83 | let user = await User.findOne({where: {email: email}}); |
85 | 84 | 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; |
89 | 88 | if(!passwordMatch) { |
90 | 89 | return {success: false, error: "Invalid credentials"};; |
91 | 90 | }else{ |
|
0 commit comments