zoukankan      html  css  js  c++  java
  • bcryptjs

    同步用法

    To hash a password:

    var bcrypt = require('bcryptjs');
    var salt = bcrypt.genSaltSync(10);
    var hash = bcrypt.hashSync("B4c0//", salt);
    // Store hash in your password DB.

    To check a password:

    // Load hash from your password DB.
    bcrypt.compareSync("B4c0//", hash); // true
    bcrypt.compareSync("not_bacon", hash); // false

    Auto-gen a salt and hash:

    var hash = bcrypt.hashSync('bacon', 8);

    异步用法

    To hash a password:

    var bcrypt = require('bcryptjs');
    bcrypt.genSalt(10, function(err, salt) {
        bcrypt.hash("B4c0//", salt, function(err, hash) {
            // Store hash in your password DB.
        });
    });

    To check a password:

    // Load hash from your password DB.
    bcrypt.compare("B4c0//", hash, function(err, res) {
        // res == true
    });
    bcrypt.compare("not_bacon", hash, function(err, res) {
        // res = false
    });

    Auto-gen a salt and hash:

    bcrypt.hash('bacon', 8, function(err, hash) {
    });
  • 相关阅读:
    4月21日Java作业
    5.14 Java作业
    第十周java作业
    4月30号作业
    第七周上机
    4.9Java
    通宵看剧有感
    error: pathspec 'xxxxxxxxx' did not match any file(s) known to git
    markdown格式测试
    博客申请通过啦
  • 原文地址:https://www.cnblogs.com/surahe/p/5249894.html
Copyright © 2011-2022 走看看