2022-06-24 02:00:17 -05:00
|
|
|
import * as bcrypt from 'bcrypt';
|
2022-04-21 17:49:08 -05:00
|
|
|
import { Injectable } from '@nestjs/common';
|
|
|
|
|
import { ConfigService } from '@nestjs/config';
|
|
|
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
|
export class BcryptService {
|
|
|
|
|
constructor(private configService: ConfigService) {}
|
|
|
|
|
|
|
|
|
|
encriptar(password: string) {
|
|
|
|
|
const salt = bcrypt.genSaltSync(
|
2022-05-02 14:40:17 -05:00
|
|
|
parseInt(this.configService.get<string>('SALT_ROUNDS')),
|
2022-04-21 17:49:08 -05:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return bcrypt.hashSync(password, salt);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
comparar(password: string, passwordDb: string) {
|
|
|
|
|
return bcrypt.compareSync(password, passwordDb);
|
|
|
|
|
}
|
|
|
|
|
}
|