Skip to content

Instantly share code, notes, and snippets.

@bantic
Created March 16, 2019 17:09
Show Gist options
  • Save bantic/0e053e4c2c73810f6602d37df1546b39 to your computer and use it in GitHub Desktop.
Save bantic/0e053e4c2c73810f6602d37df1546b39 to your computer and use it in GitHub Desktop.
// assume we have a hash function called "hash"
// this is the array of already-stored data
let data = [{
url: 'google.com',
salt: 'asdf1234',
hashed_pw: '134hsfdo'
}, {
url: 'cnn.com',
salt: '123489asdf',
hashed_pw: '14haef135'
}];
function check_password(password) {
let matched_urls = [];
for (let datum of data) {
if (hash(`${password}${datum.salt}`) === datum.hashed_pw) {
matched_urls.push(datum.url); // this is a match!
}
}
return matched_urls;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment