Created
April 28, 2018 06:18
-
-
Save tehshane/c8ab71798560045d0401e5a92b06d44b to your computer and use it in GitHub Desktop.
Snippet to check a password against the Have I Been Pwned API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const PASSWORD = ''; | |
const crypto = require('crypto') | |
const shasum = crypto.createHash('sha1') | |
const http = require('https'); | |
shasum.update(PASSWORD); | |
const hash = shasum.digest('hex').toUpperCase(); | |
http.get('https://api.pwnedpasswords.com/range/' + hash.substr(0,5), res => { | |
const chunks = []; | |
res.on('data', data => chunks.push(data)); | |
res.on('end', () => { | |
const hashes = Buffer | |
.concat(chunks) | |
.toString() | |
.split('\r\n') | |
.filter(line => line.includes(hash.substring(6))) | |
.join('\n'); | |
console.log(hashes || 'You good'); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment