Skip to content

This is a very basic module for hashing and verifying passwords.

Notifications You must be signed in to change notification settings

DreamTexX/nestjs-crypto

Repository files navigation

NestJS Password Crypto

This is a very basic module for hashing and verifying password.

Installation

With npm

$ npm install --save @dreamtexx/nestjs-crypto

With yarn

$ yarn add @dreamtexx/nestjs-crypto

Usage

Import CryptoModule in your root module.

app.module.ts

import { Module } from '@nestjs/common';
import { CryptoModule } from '@dreamtexx/nestjs-crypto';

@Module({
  imports: [
    CryptoModule.forRoot({
      pepper: 'SomeSecretString', //required
      saltLength: 16, //optional, default 16
      keyLength: 64, //optional, default 64
      delimiter: ':', //optional, default ':'
    }),
  ],
})
export class AppModule {}

Use CryptoService to hash or verify passwords.

app.service.ts

import { Injectable } from '@nestjs/common';
import { CryptoService } from '@dreamtexx/nestjs-crypto';

@Injectable()
export class AppService {
  constructor(private cryptoService: CryptoService) {}

  public getHash(password): string {
    return this.cryptoService.hash(password);
  }

  public checkPassword(password): boolean {
    // get hash from database for example:
    const hash = "...";
    return this.cryptoService.verify(password, hash);
  }
}

About

This is a very basic module for hashing and verifying passwords.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published