79152335

Date: 2024-11-03 08:46:33
Score: 1.5
Natty:
Report link

A simple solution is to use these function :

For typescript

import * as bcrypt from 'bcrypt';

const cryptPassword = (plaintextPassword: string) => {
    const salt = bcrypt.genSaltSync(10);
    return bcrypt.hashSync(plaintextPassword, salt);
}

const comparePassword = (plaintextPassword: string, hashword: string) => {
    return bcrypt.compareSync(plaintextPassword, hashword);
}

export {
    cryptPassword,
    comparePassword
};

Using js

var bcrypt = require('bcrypt');

const cryptPassword = (plaintextPassword) => {
    const salt = bcrypt.genSaltSync(10);
    return bcrypt.hashSync(plaintextPassword, salt);
}

const comparePassword = (plaintextPassword, hashword) => {
    return bcrypt.compareSync(plaintextPassword, hashword);
}

export {
    cryptPassword,
    comparePassword
};

Thanks to https://stackoverflow.com/a/14015883/22469248

Reasons:
  • Blacklisted phrase (0.5): Thanks
  • Blacklisted phrase (1): stackoverflow
  • Whitelisted phrase (-1): solution is
  • Probably link only (1):
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: Patrick Zocli