@@ -33,6 +33,7 @@ import { isEmail } from 'class-validator';
3333import { Request } from 'express' ;
3434import Redis from 'ioredis' ;
3535import assert from 'node:assert' ;
36+ import crypto from 'node:crypto' ;
3637import { AnswerService } from '../answer/answer.service' ;
3738import {
3839 InvalidCredentialsError ,
@@ -131,7 +132,8 @@ export class UsersService {
131132 private generateVerifyCode ( ) : string {
132133 let code : string = '' ;
133134 for ( let i = 0 ; i < 6 ; i ++ ) {
134- code += Math . floor ( Math . random ( ) * 10 ) . toString ( ) [ 0 ] ;
135+ const randomByte = crypto . randomBytes ( 1 ) [ 0 ] ;
136+ code += ( randomByte % 10 ) . toString ( ) ;
135137 }
136138 return code ;
137139 }
@@ -1859,7 +1861,7 @@ export class UsersService {
18591861 providerUserId : string ,
18601862 ) : string {
18611863 const timestamp = Date . now ( ) ;
1862- const random = Math . random ( ) . toString ( 36 ) . substring ( 2 ) ;
1864+ const random = crypto . randomBytes ( 8 ) . toString ( 'hex' ) ;
18631865 return `oauth_${ type } _${ providerId } _${ providerUserId } _${ timestamp } _${ random } ` ;
18641866 }
18651867
@@ -2040,7 +2042,7 @@ export class UsersService {
20402042 userId,
20412043 providerId,
20422044 providerUserId : userInfo . id ,
2043- rawProfile : userInfo ,
2045+ rawProfile : userInfo as any ,
20442046 } ,
20452047 } ) ;
20462048 }
@@ -2260,7 +2262,8 @@ export class UsersService {
22602262 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*' ;
22612263 let password = '' ;
22622264 for ( let i = 0 ; i < 16 ; i ++ ) {
2263- password += chars . charAt ( Math . floor ( Math . random ( ) * chars . length ) ) ;
2265+ const randomByte = crypto . randomBytes ( 1 ) [ 0 ] ;
2266+ password += chars . charAt ( randomByte % chars . length ) ;
22642267 }
22652268 return password ;
22662269 }
0 commit comments