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
+42
View File
@@ -17,6 +17,7 @@
"@nestjs/passport": "^11.0.5",
"@nestjs/platform-express": "^11.0.1",
"@nestjs/typeorm": "^11.0.0",
"bcrypt": "^6.0.0",
"mysql2": "^3.15.2",
"passport": "^0.7.0",
"passport-google-oauth20": "^2.0.0",
@@ -30,6 +31,7 @@
"@nestjs/cli": "^11.0.0",
"@nestjs/schematics": "^11.0.0",
"@nestjs/testing": "^11.0.1",
"@types/bcrypt": "^6.0.0",
"@types/express": "^5.0.0",
"@types/jest": "^30.0.0",
"@types/node": "^22.10.7",
@@ -2663,6 +2665,15 @@
"@babel/types": "^7.28.2"
}
},
"node_modules/@types/bcrypt": {
"version": "6.0.0",
"resolved": "https://registry.npmjs.org/@types/bcrypt/-/bcrypt-6.0.0.tgz",
"integrity": "sha512-/oJGukuH3D2+D+3H4JWLaAsJ/ji86dhRidzZ/Od7H/i8g+aCmvkeCc6Ni/f9uxGLSQVCRZkX2/lqEFG2BvWtlQ==",
"dev": true,
"dependencies": {
"@types/node": "*"
}
},
"node_modules/@types/body-parser": {
"version": "1.19.6",
"resolved": "https://registry.npmjs.org/@types/body-parser/-/body-parser-1.19.6.tgz",
@@ -4002,6 +4013,19 @@
"baseline-browser-mapping": "dist/cli.js"
}
},
"node_modules/bcrypt": {
"version": "6.0.0",
"resolved": "https://registry.npmjs.org/bcrypt/-/bcrypt-6.0.0.tgz",
"integrity": "sha512-cU8v/EGSrnH+HnxV2z0J7/blxH8gq7Xh2JFT6Aroax7UohdmiJJlxApMxtKfuI7z68NvvVcmR78k2LbT6efhRg==",
"hasInstallScript": true,
"dependencies": {
"node-addon-api": "^8.3.0",
"node-gyp-build": "^4.8.4"
},
"engines": {
"node": ">= 18"
}
},
"node_modules/bl": {
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/bl/-/bl-4.1.0.tgz",
@@ -7660,6 +7684,14 @@
"integrity": "sha512-AGK2yQKIjRuqnc6VkX2Xj5d+QW8xZ87pa1UK6yA6ouUyuxfHuMP6umE5QK7UmTeOAymo+Zx1Fxiuw9rVx8taHQ==",
"dev": true
},
"node_modules/node-addon-api": {
"version": "8.5.0",
"resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-8.5.0.tgz",
"integrity": "sha512-/bRZty2mXUIFY/xU5HLvveNHlswNJej+RnxBjOMkidWfwZzgTbPG1E3K5TOxRLOR+5hX7bSofy8yf1hZevMS8A==",
"engines": {
"node": "^18 || ^20 || >= 21"
}
},
"node_modules/node-emoji": {
"version": "1.11.0",
"resolved": "https://registry.npmjs.org/node-emoji/-/node-emoji-1.11.0.tgz",
@@ -7669,6 +7701,16 @@
"lodash": "^4.17.21"
}
},
"node_modules/node-gyp-build": {
"version": "4.8.4",
"resolved": "https://registry.npmjs.org/node-gyp-build/-/node-gyp-build-4.8.4.tgz",
"integrity": "sha512-LA4ZjwlnUblHVgq0oBF3Jl/6h/Nvs5fzBLwdEF4nuxnFdsfajde4WfxtJr3CaiH+F6ewcIB/q4jQ4UzPyid+CQ==",
"bin": {
"node-gyp-build": "bin.js",
"node-gyp-build-optional": "optional.js",
"node-gyp-build-test": "build-test.js"
}
},
"node_modules/node-int64": {
"version": "0.4.0",
"resolved": "https://registry.npmjs.org/node-int64/-/node-int64-0.4.0.tgz",
+2
View File
@@ -28,6 +28,7 @@
"@nestjs/passport": "^11.0.5",
"@nestjs/platform-express": "^11.0.1",
"@nestjs/typeorm": "^11.0.0",
"bcrypt": "^6.0.0",
"mysql2": "^3.15.2",
"passport": "^0.7.0",
"passport-google-oauth20": "^2.0.0",
@@ -41,6 +42,7 @@
"@nestjs/cli": "^11.0.0",
"@nestjs/schematics": "^11.0.0",
"@nestjs/testing": "^11.0.1",
"@types/bcrypt": "^6.0.0",
"@types/express": "^5.0.0",
"@types/jest": "^30.0.0",
"@types/node": "^22.10.7",
+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,