Skip to content

Commit 46c483c

Browse files
alainabbastacxou
authored andcommitted
save
1 parent 26568bd commit 46c483c

File tree

3 files changed

+77
-12
lines changed

3 files changed

+77
-12
lines changed

src/management/passwd/dto/reset-by-code-dto.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export class ResetByCodeDto {
66
@ApiProperty({ example: '3F4AC...', description: 'Token received by initreset' })
77
token: string;
88

9-
@IsNumber
9+
@IsNumber()
1010
@ApiProperty({ example: '123456', description: 'Code received by email or Sms' })
1111
code: number;
1212
@IsString()

src/management/passwd/passwd.service.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,11 @@ interface CipherData {
3333
export class PasswdService extends AbstractService {
3434
public static readonly RANDOM_BYTES_K = 16;
3535
public static readonly RANDOM_BYTES_IV = 12;
36-
public static readonly RANDOM_BYTES_CODE = 5;
3736

3837
public static readonly TOKEN_ALGORITHM = 'aes-256-gcm';
3938

4039
public static readonly TOKEN_EXPIRATION = 604800;
41-
public static readonly CODE_EXPIRATION = 900;
42-
public static readonly CODE_PADDING = '000000000000000000000000000'
40+
public static readonly CODE_EXPIRATION = 1900;
4341
public constructor(
4442
protected readonly backends: BackendsService,
4543
protected readonly identities: IdentitiesService,
@@ -131,9 +129,7 @@ export class PasswdService extends AbstractService {
131129
throw new BadRequestException({
132130
message: 'Erreur serveur lors de l envoi du mail',
133131
error: "Bad Request",
134-
statusCode: 400,
135-
job,
136-
_debug,
132+
statusCode: 400
137133
});
138134
})
139135

@@ -226,19 +222,20 @@ export class PasswdService extends AbstractService {
226222
token=decodeURIComponent(token)
227223
const result = await this.redis.get(token);
228224
const cypherData: TokenData = JSON.parse(result);
229-
225+
this.logger.log('decrypt ' +cypherData)
230226
if (cypherData?.iv === undefined || cypherData?.k === undefined || cypherData?.tag === undefined) {
231227
throw new NotFoundException('Invalid token');
232228
}
233-
const padd=this.getPaddingForCode();
229+
const padd=await this.getPaddingForCode();
234230
const k=padd + code.toString(16)
231+
this.logger.log('k=' + k)
235232
const decipher = crypto.createDecipheriv(PasswdService.TOKEN_ALGORITHM, k, cypherData.iv);
236233
decipher.setAuthTag(Buffer.from(cypherData.tag, 'base64'));
237234
const plaintext = decipher.update(token, 'base64', 'ascii');
238235
return JSON.parse(plaintext);
239236
} catch (error) {
240-
this.logger.verbose("Error while decrypting token. " + error + ` (token=${token})`);
241-
throw new BadRequestException('Invalid token');
237+
this.logger.error("Error while decrypting token. " + error + ` (token=${token})`);
238+
throw new BadRequestException('Invalid token xx');
242239
}
243240
}
244241
public async decryptToken(token: string): Promise<CipherData> {
@@ -262,13 +259,15 @@ export class PasswdService extends AbstractService {
262259
}
263260
}
264261
public async resetByCode(data:ResetByCodeDto):Promise<[Jobs,any]>{
262+
this.logger.log('resetByCode : ' + data.token+ ' '+ data.code )
265263
const tokenData=await this.decryptTokenWithCode(data.token,data.code)
264+
this.logger.log( 'dataToken :' + tokenData)
266265
try{
267266
const identity = await this.identities.findOne({ 'inetOrgPerson.uid': tokenData.uid }) as Identities;
268267
const [_, response] = await this.backends.executeJob(
269268
ActionType.IDENTITY_PASSWORD_RESET,
270269
identity._id,
271-
{ uid: tokenData.uid, newPassword: data.newPassword, ...pick(identity, ['inetOrgPerson']) },
270+
{ uid: tokenData.uid, newPassword: data.newpassword, ...pick(identity, ['inetOrgPerson']) },
272271
{
273272
async: false,
274273
timeoutDiscard: true,
@@ -278,6 +277,7 @@ export class PasswdService extends AbstractService {
278277
);
279278

280279
if (response?.status === 0) {
280+
this.logger.log('delete key')
281281
await this.redis.del(data.token);
282282
return [_, response];
283283
}

src/settings/passwdadm/passwdadm.service.ts

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,69 @@ export class PasswdadmService extends AbstractService {
2222
}
2323
return passwordPolicies
2424
}
25+
public async checkPolicies(password: string):Promise<boolean>{
26+
const policies=this.getPolicies()
27+
if (password.length < policies.len) {
28+
this.logger.error('Password too short')
29+
return false
30+
}
31+
32+
return true
33+
}
34+
/*
35+
function checkPolicy(password) {
36+
has_len.value='highlight_off'
37+
let statut=true
38+
if (/[!@#\$%\^\&*\)\(+=._-]/.test(password) === false){
39+
pwdColor.value = 'red'
40+
iconSpecialOK(false)
41+
statut=false
42+
}else{
43+
iconSpecialOK(true)
44+
}
45+
if (/\d/.test(password) === false){
46+
pwdColor.value = 'red'
47+
iconNumberOK(false)
48+
statut=false
49+
}else{
50+
iconNumberOK(true)
51+
}
52+
if (/[a-z]/.test(password) === false){
53+
pwdColor.value = 'red'
54+
iconLowerOK(false)
55+
statut=false
56+
}else{
57+
iconLowerOK(true)
58+
}
59+
if (/[A-Z]/.test(password) === false){
60+
pwdColor.value = 'red'
61+
iconUpperOK(false)
62+
statut=false
63+
}else{
64+
iconUpperOK(true)
65+
}
66+
if (password.length < props.min) {
67+
console.log('trop court ' + props.min)
68+
iconLenOK(false)
69+
statut=false
70+
}else{
71+
iconLenOK(true)
72+
}
73+
console.log('password OK ')
74+
if (statut === true){
75+
pwdColor.value = 'green'
76+
}else {
77+
pwdColor.value = 'red'
78+
}
79+
//entropie
80+
if (complexity(password) === false){
81+
statut=false
82+
iconComplexityOK(false)
83+
}else{
84+
iconComplexityOK(true)
85+
}
86+
return statut
87+
}
88+
*/
89+
2590
}

0 commit comments

Comments
 (0)