koa 项目实战(六)注册接口加密

1.创建工具类

根目录/config/tools.js

const bcrypt = require('bcryptjs');

const tools = {
  enbcrypt(password) {
    var salt = bcrypt.genSaltSync(10);
    var hash = bcrypt.hashSync(password, salt);
    return hash;
  }
};

module.exports = tools;

2.引用

根目录/routes/api/users.js

const tools = require('../../config/tools');
...

password: tools.enbcrypt(ctx.request.body.password)

3.效果图

原文地址:https://www.cnblogs.com/crazycode2/p/11055656.html