akamsteeg / AtleX.HaveIBeenPwned

A modern, fully async, high performance, .NET client library for the API of HaveIBeenPwned.com
https://www.nuget.org/packages/AtleX.HaveIBeenPwned/
MIT License
5 stars 0 forks source link

GetBreachesAsync returns type instead of value. #40

Closed gvasilakiss closed 4 years ago

gvasilakiss commented 4 years ago

For some reason, I get a message like this: Atle.HaveIBeenPwned.Breach Can you help me?

akamsteeg commented 4 years ago

@gvasilakiss You closed the issue, but I was wondering if you have found a bug in your own code or if there's a problem with the AtleX.HaveIBeenPwned library?

gvasilakiss commented 4 years ago

@akamsteeg It was my problem, your code is absolutely fine! I wasn't converting it from JSON to a string and that's why I was getting that error.

akamsteeg commented 4 years ago

Ah okay. :) Thanks for the response! I understand you just used a Breach object and used it as a string or called ToString() on it? I was thinking, maybe I should override ToString() on Breach and so it just outputs the value of the Name property instead of the type name.

Thanks again for the feedback.

gvasilakiss commented 4 years ago

Yeah, that's what I was trying to do, and then I found out I have to do it with the use of JSON! @akamsteeg Actually, if you make this changes it would be much simpler then to output the only the value of the name!

akamsteeg commented 4 years ago

I'm not sure about the JSON part you mentioned? There's no JSON returned from the library and to get the name of the breach you could just use the Name property. Maybe you're doing that right now and that fixed your issue? A code sample might help clear up the confusion. :)

In any case, I opened #41 for overriding ToString() on Breach and Paste and I put it on the 5.0.0 milestone. I'll probably release a beta version of that sometime the next couple of days.

gvasilakiss commented 4 years ago

Okay, see what I'm doing currently to get only the value and give me some feedback.

I wanted to get only the value of the name so I wrote this code:

public class GetBreachName { public string Name { get; set; } }

string breachesString = JsonConvert.SerializeObject(breach); GetBreachName getOnlyName = JsonConvert.DeserializeObject<GetBreachName>(breachesString);

And then I add all the links to a list

lstAddBreaches.Items.Add("Website: " + getOnlyName.Name);

What do you think, is this right?

akamsteeg commented 4 years ago

Ah cool, now I totally understand what you're doing. :) Thanks for the example. 👍

I don't think you need that GetBreachName class and serializing the Breach objects to JSON and deserializing them back to your GetBreachName objects. A Breach is already a fully fledged object with a Name property you can use. :)

Maybe this helps:


var settings = new HaveIBeenPwnedClientSettings()
{
  ApiKey = "", // Insert your API key here. If you're a student, please let me know. I'm providing one 1-month API key free of charge for every student that provides meaningful feedback.
};
using (var client = new HaveIBeenPwnedClient(settings))
{
  var lstAddBreaches = new List<string>();

  var allBreachesForEmail = await client.GetBreachesAsync("EMAIL ADDRESS");

  foreach (var currentBreach in allBreachesForEmail)
  {
    lstAddBreaches.Add("Website: " + currentBreach.Name);
  }
}

It's a bit pseudo code, but maybe it helps. :)

Please, keep asking any questions you have. I'm happy to help!

gvasilakiss commented 4 years ago

Can we talk from somewhere else, also yes I am a student!

If we move somewhere else to talk, I can tell you more details about my project too!

akamsteeg commented 4 years ago

Can we talk from somewhere else, also yes I am a student!

Yes, but I prefer email or GitHub issues. What are your proposing? Also, I'm in the Amsterdam (currently UTC+1) timezone so there might be some delay in answering. :)

Regarding the API key, if you drop me an email on alex@atlex.nl I'll send you one. :) If you already purchased an API key, let me know when it expires. I'll try to send you one that's valid for 1 month from that date onward.

gvasilakiss commented 4 years ago

Okay, let's continue from here then. I have an API key, for now, when it expires, I will drop you an email for a new one. I'm in the UK currently, so not so big problem the timezone I think.

What I am trying to do is to create a windows app and check from there if your email is pasted or pawned and also check if your password has been leaked.

Later on, I will add a function to check how "secure" is your password!

akamsteeg commented 4 years ago

Sounds like a cool project. :D Maybe the code sample I gave earlier will help you out with displaying the breaches, For a paste, you can use the Title property as a nice display name. :)

If you have any further questions about using this library, I'm happy to help. :)

For the security check on the password, maybe it's a good idea to look at the latest NIST guidelines regarding passwords. You can check the password against those recommendations and maybe calculate a value for security from it.

I won't be online much the next couple of days unfortunately but I'll try to answer any questions as quickly as I can.

gvasilakiss commented 4 years ago

Okay then, thanks so much for your feedback!

gvasilakiss commented 4 years ago

Hello mate, can you check your emails!