From e1041e9b5bbabc760f4caa337a8284d86d037a44 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Wed, 28 Feb 2018 10:58:34 -0500 Subject: [PATCH] cleanup auditservice --- src/services/audit.service.ts | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/services/audit.service.ts b/src/services/audit.service.ts index f91da9c76d..8c5479d5b1 100644 --- a/src/services/audit.service.ts +++ b/src/services/audit.service.ts @@ -3,24 +3,21 @@ import { CryptoService } from '../abstractions/crypto.service'; const PwnedPasswordsApi = 'https://api.pwnedpasswords.com/range/'; export class AuditService { - constructor(private cryptoService: CryptoService) { } async passwordLeaked(password: string): Promise { const hash = (await this.cryptoService.sha1(password)).toUpperCase(); - - const response = await fetch(PwnedPasswordsApi + hash.substr(0, 5)); - const leakedHashes = await response.text(); - + const hashStart = hash.substr(0, 5); const hashEnding = hash.substr(5); - const match = leakedHashes - .split(/\r?\n/) - .find((v) => { - return v.split(':')[0] === hashEnding; - }); + const response = await fetch(PwnedPasswordsApi + hashStart); + const leakedHashes = await response.text(); - return match ? parseInt(match.split(':')[1], 10) : 0; + const match = leakedHashes.split(/\r?\n/).find((v) => { + return v.split(':')[0] === hashEnding; + }); + + return match != null ? parseInt(match.split(':')[1], 10) : 0; } }