0.0.5 • Published 1 year ago

@dreamtexx/nestjs-crypto v0.0.5

Weekly downloads
5
License
ISC
Repository
github
Last release
1 year ago

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);
  }
}
0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago