Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mattiamalonni/sequelize-bcrypt
https://github.com/mattiamalonni/sequelize-bcrypt
bcrypt sequelize sequelize-extension sequelize-plugin
Last synced: 14 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/mattiamalonni/sequelize-bcrypt
- Owner: mattiamalonni
- License: mit
- Created: 2021-11-03T14:11:27.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2022-08-24T13:24:04.000Z (about 2 years ago)
- Last Synced: 2024-11-01T00:47:11.918Z (20 days ago)
- Topics: bcrypt, sequelize, sequelize-extension, sequelize-plugin
- Language: JavaScript
- Homepage:
- Size: 25.4 KB
- Stars: 11
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# sequelize-bcrypt
## Installation
```bash
npm i sequelize-bcrypt
```## Setup
```javascript
const { Sequelize, DataTypes } = require('sequelize');
const useBcrypt = require('sequelize-bcrypt');const database = new Sequelize({
...sequelizeConnectionOptions,
});const User = database.define('User', {
email: { type: DataTypes.STRING },
password: { type: DataTypes.STRING },
});useBcrypt(User, options);
```## Options
```javascript
{
field: 'password', // secret field to hash, default: 'password'
rounds: 12, // used to generate bcrypt salt, default: 12
compare: 'authenticate', // method used to compare secrets, default: 'authenticate'
}
```## Usage
```javascript
User.create({ email: '[email protected]', password: 'SuperSecret!' });
// { id: 1, email: '[email protected]', password: '$2a$12$VtyL7j5xx6t/GmmAqy53ZuKJ1nwPox5kHLXDaottN9tIQBsEB3EsW' }const user = await User.findOne({ where: { email: '[email protected]' } });
user.authenticate('WrongPassword!'); // false
user.authenticate('SuperSecret!'); // true
```