1.0.0 • Published 3 years ago

node-auth0 v1.0.0

Weekly downloads
58
License
-
Repository
-
Last release
3 years ago

一、node-auth0主要提供的功能

  • 1、密码加密
  • 2、校验密码是否正确

二、包的使用

  • 1、安装

    npm install node-auth0

三、使用步骤

  • 1、导包

    import NodeAuth from 'node-auth0';
    // or
    const { NodeAuth } = require('node-auth0');
  • 2、实例化对象

    class User1Dao extends BaseDao {
      constructor() {
        super();
        this.nodeAuth = new NodeAuth();
      }
      ...
    }
  • 3、密码加密的方法makePassword

    ...
    async createUser(params) {
      try {
        const { name, password } = params;
        return await UserModel.create({
          name,
          password: this.nodeAuth.makePassword(password)
        });
      } catch (e) {
        throw e;
      }
    }
  • 4、校验密码的方法checkPassword

    async login(params) {
      try {
        const { name, password } = params;
        const user = await UserModel.findOne({
          where: {
            name
          }
        });
        // 第一个参数是普通密码,第二个参数是加密后的密码
        if (this.nodeAuth.checkPassword(password, user.password)) {
          return user;
        } else {
          throw {
            msg: '登录错误',
            desc: '用户名与密码错误'
          };
        }
      } catch (e) {
        throw {
          msg: '登录错误',
          desc: '用户名与密码错误'
        };
      }
    }
1.0.0

3 years ago

0.0.8

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.1

3 years ago

0.0.0

3 years ago

2.0.0-alpha.0

9 years ago