dcodeIO / bcrypt.js

Optimized bcrypt in plain JavaScript with zero dependencies.
Other
3.51k stars 267 forks source link

bcrypt.compare don`t work #123

Closed ganlanshu0211 closed 4 years ago

ganlanshu0211 commented 4 years ago

I ran into a problem. Today, I refer to this article to refresh my tokens in nestjs,however,the tokens I signed this morning passed my authorization. So,I write a short test

var accessToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJtb2JpbGUiOiIxODgyNTA3ODE5MCIsInN1YiI6MSwiaWF0IjoxNjAxMjY0Nzc1LCJleHAiOjE2MDEzMDA3NzV9.i4o9b8Idi7-xjFQESrd2Bq6nAzqfAlHGnLpql9NC31M';

var accessToken1 = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJtb2JpbGUiOiIxODgyNTA3ODE5MCIsInN1YiI6MSwiaWF0IjoxNjAxMjk1MTA2LCJleHAiOjE2MDEzMzExMDZ9.6DuqM1Knq8K5LgvWwU0HToMOGfa_irflYPGU4TPS8mo';

var hash = '$2b$10$gzTK9l4A48vrhn.QYI3BjOonpeF8iqbvh4UKB1MCc585gMIPy7MiK';

const isaccessTokenMatching = await bcrypt.compare(
  accessToken,
  hash
);
console.log(isaccessTokenMatching);

const isaccessTokenMatching1 = await bcrypt.compare(
  accessToken1,
  hash
);
console.log(isaccessTokenMatching1);

Then,I get two true in my terminal. What I did wrong?

I am using bcrypt 5.0.0

Thanks for your help!