Skip to content

Commit

Permalink
add check for handling error in decrption function
Browse files Browse the repository at this point in the history
  • Loading branch information
yuvrajsab committed Nov 17, 2023
1 parent 20beac4 commit eb4b142
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/api/api.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,20 @@ export class ApiController {
encodedBase64Key === undefined
? CryptoJS.enc.Base64.parse('bla')
: CryptoJS.enc.Base64.parse(encodedBase64Key);
const loginId = this.apiService.decrypt(user.loginId, parsedBase64Key);
const password = this.apiService.decrypt(user.password, parsedBase64Key);

let loginId = '';
try {
loginId = this.apiService.decrypt(user.loginId, parsedBase64Key);
} catch (e) {
console.log(`Problem in decoding loginId: ${user.loginId}`);
}

let password = '';
try {
password = this.apiService.decrypt(user.password, parsedBase64Key);
} catch (e) {
console.log(`Problem in decoding password: ${user.password}`);
}

// if we are not able to decrypt, we'll try to authenticate with the original creds
user.loginId = loginId ? loginId : user.loginId;
Expand Down

0 comments on commit eb4b142

Please sign in to comment.