egg-bcrypt

egg bcrypt plugin

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
egg-bcrypt
1.1.05 years ago5 years agoMinified + gzip package size for egg-bcrypt in KB

Readme

egg-bcrypt
!NPM versionnpm-imagenpm-url !build statustravis-imagetravis-url !Test coveragecodecov-imagecodecov-url !David depsdavid-imagedavid-url !Known Vulnerabilitiessnyk-imagesnyk-url !npm downloaddownload-imagedownload-url
bcrypt plugin for egg, based on bcrypt (Optimized bcrypt in JavaScript with zero dependencies.)

Install

$ npm i egg-bcrypt --save

Configuration

  • config.default.js
exports.bcrypt = {
  saltRounds: 10 // default 10
}
  • config/plugin.js
// {app_root}/config/plugin.js
exports.bcrypt = {
  enable: true,
  package: 'egg-bcrypt'
}

Usage


@params plainText(string)
@return Promise
```js ctx.genHash(plainText) ```
  • async To check a password
@params plainText (string)
@params hash (string)
@return Boolean true/false
```js ctx.compare(plainText, hash) ```
  • example

```js
// {app_root}/app/contoller/user.js
...
async generate() {
  const hash = await this.ctx.genHash(this.ctx.request.body.plainText);
  // Store hash in your password DB
  ...
}

async compare() {
  const { hash, plainText } = this.ctx.request.body;
  const checked = await this.ctx.compare(plainText, hash);
  this.ctx.body = { checked };
} 
...
```

License

MIT