Skip to content

Instantly share code, notes, and snippets.

@architjn
Created January 17, 2019 05:30
Show Gist options
  • Save architjn/3be15dca4be56ce7f980b3e93858bbe6 to your computer and use it in GitHub Desktop.
Save architjn/3be15dca4be56ce7f980b3e93858bbe6 to your computer and use it in GitHub Desktop.
function make_base_auth(user, password) {
var tok = user + ':' + password;
var hash = btoa(tok);
return "Basic " + hash;
}
$.ajax({
url: "https://haveibeenpwned.com/api/v2/breachedaccount/" + data.email,
method: "GET",
dataType: "json",
beforeSend: function (xhr){
xhr.setRequestHeader('Authorization', make_base_auth(username, password));
},
success: function(msg){
if(typeof mprogress != 'undefined'){
mprogress.end(true);
}
clearRecords();
msg.forEach(function(detail){
addRecord(detail);
});
showRecords();
},
error: function(jqXHR, textStatus, errorThrown){
if(typeof mprogress != 'undefined'){
mprogress.end(true);
}
if(jqXHR.status == 404){
$('#records').html('No Records Found.');
showRecords();
}
// showAPIError(jqXHR.status, (jqXHR.responseJSON?jqXHR.responseJSON:(jqXHR.responseText === "Unauthorized"?{errors: ['Invalid Credentials']}:jqXHR.responseText)));
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment