21 lines
526 B
TypeScript
21 lines
526 B
TypeScript
import { Injectable } from '@nestjs/common';
|
|
import { ConfigService } from '@nestjs/config';
|
|
import * as bcrypt from 'bcrypt';
|
|
|
|
@Injectable()
|
|
export class BcryptService {
|
|
constructor(private configService: ConfigService) {}
|
|
|
|
encriptar(password: string) {
|
|
const salt = bcrypt.genSaltSync(
|
|
parseInt(this.configService.get<string>('SALT_ROUNDS')),
|
|
);
|
|
|
|
return bcrypt.hashSync(password, salt);
|
|
}
|
|
|
|
comparar(password: string, passwordDb: string) {
|
|
return bcrypt.compareSync(password, passwordDb);
|
|
}
|
|
}
|