added hased password

This commit is contained in:
2025-10-17 12:28:31 -06:00
parent fd381b5c29
commit 10d71b19d1
4 changed files with 65 additions and 6 deletions
+10
View File
@@ -0,0 +1,10 @@
export default function passwordRand(length: number): string {
const characters =
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
let pass = '';
for (let i = 0; i < length; i++) {
pass += characters.charAt(Math.floor(Math.random() * characters.length));
}
return pass;
}
+11 -6
View File
@@ -3,6 +3,9 @@ import { JwtService } from '@nestjs/jwt';
import { Repository } from 'typeorm';
import { InjectRepository } from '@nestjs/typeorm';
import { Persona } from './entities/persona.entity';
import * as bcrypt from 'bcrypt';
import passwordRand from './password';
@Injectable()
export class PersonaService {
constructor(
@@ -36,7 +39,7 @@ export class PersonaService {
let persona = await this.findByEmail(data.email);
if (!persona) {
const apellidoArray = data.apellido.trim().split(' ');
const apellidoArray = data.apellido.split(' ');
const apellidoP = data.apellido[0] || '';
const apellidoM = data.apellido[1] || '';
const nombre = apellidoArray.slice(2).join(' ') || '';
@@ -44,19 +47,21 @@ export class PersonaService {
// Número identificador del correo
const numeroIdentificar = data.email.split('@')[0];
const password = await passwordRand(12);
let hash = await bcrypt.hashSync(password, 13);
persona = await this.create({
nombre: nombre || '',
apellidoP: apellidoP || '',
apellidoM: apellidoM || '',
password: '',
passwordTem: '',
password: hash,
fechaPasswordTem: new Date(),
correo: data.email,
carreraAds: '',
carreraAds: 'Mac',
cantidadCuenta: 0,
usuario: '',
usuario: numeroIdentificar || '',
numeroIdentificar: numeroIdentificar || '',
tipoUsuario: '',
tipoUsuario: 'Alumno',
correoEnviado: false,
fechaRegistro: new Date(),
cambioPasswordReq: true,