1.1.0 • Published 6 years ago

haveibeenpwned v1.1.0

Weekly downloads
2
License
Unlicense
Repository
github
Last release
6 years ago

haveibeenpwned

API methods for Have I been pwned (unofficial)

npm Build Status Coverage Status bitHound Dependencies bitHound Code Greenkeeper badge

Example

const hibp = require ('haveibeenpwned') ();

hibp.breachedAccount ('foo@bar.com', (err, data) => {
  if (err) {
    return console.log (err);
  }

  console.log (data);
});

Installation

npm i haveibeenpwned

Configuration

nametyperequireddefaultdescription
timeoutnumberno5000Request wait timeout in ms
const pwned = require ('haveibeenpwned') ({
  timeout: 10000
});

Have I Been Pwned

Below are the methods for the main Have I Been Pwned API.

For simplicity no error handling is included in the callback examples. It's straightforward: when there is a problem err is an instance of Error and data is undefined, otherwise err is null and data is set to the result.

.breachedAccount

( account, params, callback )

All breaches for an account.

argumenttyperequireddescription
accountstringyesEmail or username to check
paramsobjectnoAdditional parameters to include
callbackfunctionyesfunction (err, data) {}
hibp.breachedAccount ('foo@bar.com', yourCallback);

Example output

.breaches

( params, callback )

All breaches in the system.

argumenttyperequireddescription
paramsobjectnoAdditional parameters to include
callbackfunctionyesfunction (err, data) {}
hibp.breaches (yourCallback);

Example output

.breach

( name, params, callback )

A single breached site.

argumenttyperequireddescription
namestringyesSite name to check, i.e. linkedin
paramsobjectnoAdditional parameters to include
callbackfunctionyesfunction (err, data) {}
hibp.breach ('Adobe', yourCallback);

Example output

.pasteAccount

( account, callback )

All pastes for an account.

argumenttyperequireddescription
accountstringyesEmail or username to check
callbackfunctionyesfunction (err, data) {}
hibp.pasteAccount ('foo@bar.com', yourCallback);

Example output

.dataclasses

( callback )

All pastes for an account.

argumenttyperequireddescription
callbackfunctionyesfunction (err, data) {}
hibp.dataclasses (yourCallback);

Example output

Pwned Passwords

Below are the methods for the Pwned Passwords API.

.pwnedpasswords.byPassword

( password, hashed, callback )

Check if a password was leaked. The data is 0 (int) when none were found.

argumenttypedefaultdescription
passwordstringThe password to check
hashedboolfalseIs the password already SHA-1 hashed
callbackfunction(err, data)
hibp.pwnedpasswords.byPassword ('secret', (err, count) => {
  if (!count) {
    console.log ('Great! Password is not found.');
  } else {
    console.log ('Oops! Password was found ' + count + ' times!');
  }
});

// -> Oops! Password was found 195263 times!

.pwnedpasswords.byRange

( hash, sort, callback )

Get password hashes similar to the first 5 characters of the SHA-1 hash provided. The callback data is an object where the keys are the lowercase hashes and the values are the number of times they were used. When nothing is found data is 0 (int).

A hash longer then 5 characters is truncated before being sent to the API and can be in uppercase or lowercase.

argumenttypedefaultdescription
hashstringThe SHA-1 hash to check
sortboolfalseSort by counts in descending order
callbackfunction(err, data)

Sorted by key (default)

hibp.pwnedpasswords.byRange ('abcdef', (err, data) => {
  for (sha in data) {
    console.log ('%s  %i x', sha, data[sha]);
  }
});

Sorted by use counts

hibp.pwnedpasswords.byRange ('abcdef', true, (err, data) => {
  const count = Object.keys (data).length;
  let i = 1;

  console.log ('Found %i matches', count);
  console.log ('Top 3:');

  for (sha in data) {
    console.log ('%i  %s  %i x', i, sha, data[sha]);

    // stop after 3
    if (i === 3) { break; }
    i++;
  }
});

// ->
// Found 511 matches
// Top 3:
// 1  3b8a55c2b3bf42b83e41f0f95a4149043f6  336 x
// 2  6a7fc410810db77855d9dfe5b94b95196f7  304 x
// 3  73a1a21a7b13b50536df19fd586abdf3145  193 x

Unicense

This is free and unencumbered software released into the public domain.

Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a compiled binary, for any purpose, commercial or non-commercial, and by any means.

In jurisdictions that recognize copyright laws, the author or authors of this software dedicate any and all copyright interest in the software to the public domain. We make this dedication for the benefit of the public at large and to the detriment of our heirs and successors. We intend this dedication to be an overt act of relinquishment in perpetuity of all present and future rights to this software under copyright law.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

For more information, please refer to http://unlicense.org

Author

Franklin van de Meent

Buy me a coffee