Giter Club home page Giter Club logo

Comments (3)

AbdourahamaneIssakaSani avatar AbdourahamaneIssakaSani commented on June 14, 2024 1

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.

THPubs avatar THPubs commented on June 14, 2024 1

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.

farzaadweb avatar farzaadweb commented on June 14, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.