Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

163
Views
In Javascript two same looking strings are not equal?

I'm trying to compare two passwords , one from DB and other is user entered. The one from db is hashed and stored in binary format. So I have to conver it to string before comparing.

 console.log(
      user.PasswordHash.toString('base64') ===
        '$2a$10$UZptbo5h4lQFYmK352CPf.jDvPZh1pm3uC3Nb0wEVjF/RUCw2OU2G'
    ); //false

When I look in console user.PasswordHash.toString('base64') evaluates to $2a$10$UZptbo5h4lQFYmK352CPf.jDvPZh1pm3uC3Nb0wEVjF/RUCw2OU2G which is the same value.

What is happening?

bcrypt.compareSync(
      password,
      user.PasswordHash.toString('base64')); //false

Any help is appreciated.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The problem is not in the code you are sharing.. Is somewhere else.. My thesis is that you have an asynchronous problem meaning that the data is delivered after the code is executed. In that case the variable is undefined and the conditional statement will return false as in the following example:

let x;

function isOne(input){
  return input === 1;
}

console.log(isOne(x))

Try implementing a promise https://www.w3schools.com/js/js_promise.asp

To see if it's an asynchronous problem you can use setTimeout()

Make sure you have the data and then execute your condition statement. Go step by step checking with console.log()

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!