Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const sha1 = async str => {
- const msgBuffer = new TextEncoder('utf-8').encode(str);
- const hashBuffer = await crypto.subtle.digest('SHA-1', msgBuffer);
- const hashArray = [...new Uint8Array(hashBuffer)];
- const paddedHex = hashArray.map(b => b.toString(16).padStart(2, '0'));
- return paddedHex.join('').toUpperCase();
- };
- const request = hash => {
- const prefix = hash.substring(0, 5);
- const url = 'https://api.pwnedpasswords.com/range/' + prefix;
- return {
- response: fetch(url).then(r => r.text()),
- hash: hash
- };
- };
- const search = o => {
- const suffix = o.hash.slice(5);
- return o.response.then(text => text.includes(suffix));
- };
- const hibp = pass => sha1(pass).then(request).then(search);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement