0.0.5 • Published 3 years ago

nest-pbkdf2 v0.0.5

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

Installation

npm:

npm i nest-pbkdf2

yarn:

yarn add nest-pbkdf2

Configure

app.module.ts

...
@Module({
	...
	imports: [
		...
		Pbkdf2Module.forRoot({
			// Default values
			hashBytes: 32, /* optional */
			saltBytes: 16, /* optional */
			digest: 'sha512', /* optional */
			iterations: 65535, /* optional */
			encoding: 'hex', /* optional */
		}),
		...
		// For asynchronous configuration
		...
		Pbkdf2Module.forRootAsync({
			import: [ConfigModule],
			useFactory: (config: ConfigService) => ({
				hashBytes: config.get('HASH_BYTES')
			})
			inject: [ConfigService]
		}),
		...
		// OR
		AesGcmModule.forRootAsync({
			useClass: Pbkdf2ConfigClass
		}),
		...
	],
	...
})
...

your.service.ts

...
@Injectable()
export class YourService{
	constructor(private readonly pbkdf2Service: Pbkdf2Service){
	}

	async hash(text: string): Promise<string> {
		return await this.pbkdf2Service.hash(text);
	}

	hashSync(text: string): string {
    return this.pbkdf2Service.hash(text);
	}

  async compare(password: string, hash: string): Promise<boolean> {
    return await this.pbkdf2Service.compare(password, hash);
  }

	compareSync(password: string, hash: string): boolean {
		return this.pbkdf2Service.compare(password, hash);
	}
}
...

Use Asynchronous methods for better performance

0.0.5

3 years ago

0.0.3

3 years ago

0.0.4

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago