egg-bcrypt
bcrypt plugin for egg, based on bcrypt (Optimized bcrypt in JavaScript with zero dependencies.)
Install
$ npm i egg-bcrypt --save
Configuration
- config.default.js
exportsbcrypt = saltRounds: 10 // default 10
- config/plugin.js
// {app_root}/config/plugin.jsexportsbcrypt = enable: true package: 'egg-bcrypt'
Usage
-
[async] To hash a password
@params plainText(string)
@return Promise
ctx -
[async] To check a password
@params plainText (string)
@params hash (string)
@return Boolean true/false
ctx -
example
// {app_root}/app/contoller/user.js...async {const hash = await thisctx;// Store hash in your password DB...}async {const hash plainText = thisctxrequestbody;const checked = await thisctx;thisctxbody = checked ;}...