Comments (3)
const messageController = require('@service').message; const { v4: uuidv4 } = require('uuid'); const _User = require('@model').User; const bcrypt = require('bcryptjs');
class User { async register(req, res) { let { email, firstName, lastName, password, age } = req.body if (!email || !firstName || !lastName || !password || !age) { return res.status(400).send(messageController(400)) }; let checkUser = await _User.findOne({ where: { email } }) if (checkUser) return res.status(409).send(messageController(409)); let hashedPassword = await bcrypt.hash(password, 12); try { let createUser = await _User.create({ id: uuidv4(), email, firstName, lastName, password: hashedPassword, age }) if (createUser) return res.status(201).send(messageController(201)); return res.status(422).send(messageController(422)); } catch (error) { return res.status(500).send(messageController(500)); } }
async login(req, res) { let { email, password } = req.body if (!email || !password) { return res.status(400).send(messageController(400)) }; let findUser = await _User.findOne({ where: { email } }); if (!findUser) return res.status(404).send(messageController(404, 'User Not Found', 'کاربری با این مشخصات یافت نشد')); let hashedPasswordCheck = await bcrypt.compare(password, findUser.dataValues.password) console.log(hashedPasswordCheck); if (!hashedPasswordCheck) return res.status(401).send(messageController(401)); console.log("after", hashedPasswordCheck); } }
module.exports = User;
It always returns me as false but the code is true
It does not make sense I know but remove await
and it should work
let hashedPasswordCheck = bcrypt.compare(password, findUser.dataValues.password)
Though signature of compare is function compare(s: string, hash: string): Promise<boolean>
, I hope someone can explain why these last days it fails with await
, while in the past it worked well.
from bcrypt.js.
DO NOT REMOVE AWAIT. IF you do this, it will return a promise which will always be true. Any password will work in that situation.
from bcrypt.js.
Thank you for your time. The issue stemmed from the version I had installed. A previous version was functioning properly, and it's possible that they have since updated and rectified the problem.
from bcrypt.js.
Related Issues (20)
- Trailing underscores are not accounted for. HOT 1
- Bcryptjs on browser is not functioning properly. HOT 3
- hopefully can delete email address or write them on the README.md
- Can't resolve 'crypto', BREAKING CHANGE: webpack <5 used to include polyfills? HOT 3
- Bcryptjs compares badly with jwt and its hash HOT 5
- Error: Illegal arguments: undefined, string HOT 1
- issues with compare/compareSync via docker compose env
- This repository is no longer maintained HOT 5
- How bcryptjs works?
- This library is maintained
- bcryptjs.compare returns illegal arguments error
- Error: Illegal arguments: string, undefined HOT 1
- How to decript password?????? HOT 5
- genSalt not working on nodejs esm
- Unclear license status HOT 2
- Vite: Module "crypto" has been externalized for browser compatibility
- Cannot Import from `bcryptjs` in a Playwright Test HOT 1
- Crypto With Nextjs X.X HOT 2
- Inquiry about the Current Status of the Library HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bcrypt.js.