zoukankan      html  css  js  c++  java
  • 密码加密模块bcrypt

    概述

    方便的密码加密和密码比对

    使用步骤

    依赖环境

    安装

    npm install bcrypt
    

    引入

    const bcrypt = require('bcrypt');
    

    使用

    async function run() {
        /*生成随机字符串*/
        // genSalt方法接收一个数值作为参数
        // 数值越大 生成的随机字符串复杂度越高
        // 数值越小 生成的随机字符串复杂度越低
        // 默认值是 10
        // 返回生成的随机字符串
        const salt = await bcrypt.genSalt(10);
    
        /*对密码进行加密*/
        // 1. 要进行加密的明文
        // 2. 随机字符串
        // 返回值是加密后的密码
        const result = await bcrypt.hash('123456', salt);
    
        console.log(salt); // $2b$10$8WKO8qOjtmYT5FsR1zJyGu
        console.log(result);
    }
    
    run();
    

  • 相关阅读:
    Reverse Linked List
    Sqrt(x)
    Convert Sorted Array to Binary Search Tree
    Remove Linked List Elements
    Happy Number
    Length of Last Word
    Pow(x, n)
    Rotate Image
    Permutations
    Integer to Roman
  • 原文地址:https://www.cnblogs.com/shenleg/p/14334888.html
Copyright © 2011-2022 走看看