bcrypt como servicio y login operador listo
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { BcryptService } from './bcrypt.service';
|
||||
|
||||
@Module({
|
||||
providers: [BcryptService],
|
||||
exports: [BcryptService],
|
||||
})
|
||||
export class BcryptModule {}
|
||||
@@ -0,0 +1,18 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { BcryptService } from './bcrypt.service';
|
||||
|
||||
describe('BcryptService', () => {
|
||||
let service: BcryptService;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
providers: [BcryptService],
|
||||
}).compile();
|
||||
|
||||
service = module.get<BcryptService>(BcryptService);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(service).toBeDefined();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,20 @@
|
||||
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(
|
||||
Number(this.configService.get<string>('SALT_ROUNDS')),
|
||||
);
|
||||
|
||||
return bcrypt.hashSync(password, salt);
|
||||
}
|
||||
|
||||
comparar(password: string, passwordDb: string) {
|
||||
return bcrypt.compareSync(password, passwordDb);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user