Search code examples
node.jsencryptionbcryptpassword-protectionsha

What is the best approach for password encryption


What is the best practice from frontend to backend for encrypting the password received during the registration process from the frontend. For example, should I encrypt and send on the front end and then re-encrypt on the backend? I would appreciate if you could answer in node.js specific


Solution

  •     const bcrypt = require('bcrypt');
        const SimpleCrypto = require('simple-crypto-js').default;
        const _secretKey = "YOURKEYHERE"; //key for create hash key 
        const simpleCrypto = new SimpleCrypto(_secretKey);
        const saltRounds = 12;
        
        exports.createHashPwd = function (password) {
          return bcrypt.hashSync(password, saltRounds);
        };
        
        //create hashpassword string
        const hashPassword = await passwordService.createHashPwd(plainTextPd);
    

    You can know more about it here https://www.npmjs.com/package/simple-crypto-js