fastify-bcrypt-plugin
TypeScript icon, indicating that this package has built-in type declarations

1.0.6 • Public • Published

fastify-bcrypt-plugin

Version

A Bcrypt hash generator & checker for Fastify

Installation

yarn add fastify-bcrypt-plugin
or
npm install fastify-bcrypt-plugin

Usage

Register plugin

import fastifyBcrypt from "fastify-bcrypt-plugin";

fastify.register(fastifyBcrypt);

If you use with TypeScript , you have to give this type to avoid error

import Fastify, { FastifyInstance } from "fastify";

const fastify: FastifyInstance = Fastify();

If you want to change the salt work factor

fastify.register(fastifyBcrypt, { saltOrRounds: 15 }); // The salt work factor for the bcrypt algorithm. The default value is 10.

Use with fastify decorate

fastify.get("/", async (request, reply) => {
  const hashedPassword = await fastify.bcrypt.hash(request.body.password);
  const isPasswordCompared = await fastify.bcrypt.compare(
    request.body.password,
    hashedPassword
  );
  return { hashedPassword, isPasswordCompared };
});

Use with request decorate

fastify.get("/", async (request, reply) => {
  const hashedPassword = await request.bcrypt.hash(request.body.password);
  const isPasswordCompared = await request.bcrypt.compare(
    request.body.password,
    hashedPassword
  );
  return { hashedPassword, isPasswordCompared };
});

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT

Package Sidebar

Install

npm i fastify-bcrypt-plugin

Weekly Downloads

3

Version

1.0.6

License

MIT

Unpacked Size

7.33 kB

Total Files

10

Last publish

Collaborators

  • urdux