Snippets Collections
curl --location --request GET 'api.hived.space/user/login' \
--header 'Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ=' \
--data-raw ''
const comparePassword = async (password, hash) => {
    try {
        // Compare password
        return await bcrypt.compare(password, hash);
    } catch (error) {
        console.log(error);
    }

    // Return false if error
    return false;
};

//use case
(async () => {
    // Hash fetched from DB
    const hash = `$2b$10$5ysgXZUJi7MkJWhEhFcZTObGe18G1G.0rnXkewEtXq6ebVx1qpjYW`;

    // Check if password is correct
    const isValidPass = await comparePassword('123456', hash);

    // Print validation status
    console.log(`Password is ${!isValidPass ? 'not' : ''} valid!`);
    // => Password is valid!
})();
star

Wed Jul 20 2022 13:52:54 GMT+0000 (Coordinated Universal Time)

#api #shipment #authentication
star

Wed Apr 27 2022 10:18:16 GMT+0000 (Coordinated Universal Time)

#authentication #api
star

Sun Feb 20 2022 17:47:47 GMT+0000 (Coordinated Universal Time) https://www.bezkoder.com/react-node-mongodb-auth/

#react #authentication
star

Sun Jun 06 2021 15:47:09 GMT+0000 (Coordinated Universal Time) https://attacomsian.com/blog/nodejs-password-hashing-with-bcrypt

#bcrypt #authentication #express #nodejs #password

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension