egzonmustafa
egzonmustafa

Reputation: 115

Error: data and salt arguments required (am i missing something)?

app.post('/verify', function(req, res) {
// Create a password salt
var salt = bcrypt.genSaltSync(10);
    // Salt and hash password
var passwordToSave = bcrypt.hashSync(password_login, salt)

   var user_login = req.body.email;
   var password_login = req.body.password;


        connection.query('SELECT * FROM USER WHERE email = ?',
         [user_login],
          function(err, rows) {
            if (err) {
                        return done(err);
                    }
            if (bcrypt.hashSync(password_login, salt) === rows[0].password) {
                console.log('works');
        }

        });

    });

Error: data and salt arguments required! Can someone help me? What's going on here?

As I can see I could not understand the logic of bcrypt. On MySql the password field is hashed but is not fit or as I can say it's not comparing with anything... maybe should I use compare does bycrypt use anything of that?

Upvotes: 0

Views: 2604

Answers (1)

Ryan
Ryan

Reputation: 1883

You cannot do bcrypt.hashSync(password_login, salt) == password as you are using a random salt which means it won't match the stored password.

You need to use bcrypt.compareSync(password_login, hashedPassword) hashedPassword comes from the select you ran on the database using the submitted email. (e.g. hashedPassword= rows[0].password)

Upvotes: 1

Related Questions