public UpdateService(EmailManager emailManager) { _client = new HaveIBeenPwnedRestClient(); _emailManager = emailManager; _notification = new Notification(); _sub = Observable.Interval(TimeSpan.FromDays(1));//one request per day }
static void Do(Options options) { var csvFile = options.Path; var records = new List <KeepassLayout>(); using (var reader = new StreamReader(csvFile)) { using (var csv = new CsvReader(reader)) { records = csv.GetRecords <KeepassLayout>().ToList(); } } var grouped = records.GroupBy(r => r.LoginName).Select(s => new { Login = s.Key, Records = s.ToList() }).ToList().Where(l => l.Login.Contains("@")); var client = new HaveIBeenPwnedRestClient(); foreach (var login in grouped) { var breaches = client.GetAccountBreaches(login.Login).Result; if (breaches.Any()) { Console.WriteLine($"Login: {login.Login}, Breaches: {string.Join(", ",breaches.Select(b => b.Title))}"); foreach (var record in login.Records) { var pwnedPass = client.IsPasswordPwned(record.Password).Result; if (pwnedPass) { Console.WriteLine($"Possible pwned password - Account: {record.Account}, Password: {record.Password}"); } } } } }
public PwnedEmailValidator(HaveIBeenPwnedRestClient pwned, ILogger <PwnedEmailValidator> log, IStringLocalizer <AppResources> localizer) { this.pwned = pwned; this.log = log; this.localizer = localizer; }
private string performSearchTask(BackgroundWorker worker, DoWorkEventArgs e) { var client = new HaveIBeenPwnedRestClient(); UserCredential credential; //We open the oauth setting of this app and request with browser your consent (only first time) using (var stream = new FileStream("client_secret.json", FileMode.Open, FileAccess.Read)) { string credPath = System.Environment.GetFolderPath( System.Environment.SpecialFolder.Personal); credPath = Path.Combine(credPath, ".credentials/GHBP.json"); credential = GoogleWebAuthorizationBroker.AuthorizeAsync( GoogleClientSecrets.Load(stream).Secrets, Scopes, "user", CancellationToken.None, new FileDataStore(credPath, true)).Result; Console.WriteLine("Credential file saved to: " + credPath); } // Create Gmail API service. var service = new GmailService(new BaseClientService.Initializer() { HttpClientInitializer = credential, ApplicationName = ApplicationName, }); // Define parameters of request. UsersResource.MessagesResource.ListRequest lRequest = service.Users.Messages.List(this.textBox4.Text); lRequest.LabelIds = this.textBox1.Text; lRequest.IncludeSpamTrash = this.checkBox1.Checked; lRequest.Q = this.textBox3.Text; //list of total messages coming from the query filter List <Google.Apis.Gmail.v1.Data.Message> result = new List <Google.Apis.Gmail.v1.Data.Message>(); //Distinct List of Senders Hashtable distinctSenders = new Hashtable(); do { try { //Gmail service does not give all the messages in one shot, so we have to perfom multiple request //using pagination. ListMessagesResponse response = lRequest.Execute(); result.AddRange(response.Messages); lRequest.PageToken = response.NextPageToken; } catch (Exception excp) { worker.ReportProgress(0, "An error occurred: " + excp.Message); } } while (!String.IsNullOrEmpty(lRequest.PageToken)); IList <MessagePartHeader> tempHeader = null; string emailToCheck = String.Empty; int processedMessages = 0; int totalMessages = 0; int maxRecords = System.Convert.ToInt32(this.numericUpDown1.Value); if (result != null && result.Count > 0) { totalMessages = result.Count; foreach (var messageItem in result) { System.Threading.Thread.Sleep(50); var emailInfoRequest = service.Users.Messages.Get(this.textBox4.Text, messageItem.Id); //Gmail service gives us only the message Id for each message we need another call to have the // other fields , in particular the headers var emailInfoResponse = emailInfoRequest.Execute(); if (emailInfoResponse != null) { tempHeader = emailInfoResponse.Payload.Headers; foreach (MessagePartHeader mParts in tempHeader.Where(x => x.Name == this.textBox2.Text).ToList()) { emailToCheck = ExtractString(mParts.Value); //here we build the list of distinct senders if (!distinctSenders.ContainsKey(emailToCheck)) { distinctSenders.Add(emailToCheck, null); } } processedMessages++; worker.ReportProgress(processedMessages / totalMessages, "Processed " + processedMessages + " of " + totalMessages + " total messages"); if (processedMessages >= maxRecords) { //we stop the execution if we reached the max amount of messages defined into the config break; } } } int totalSenders = 0; int processedSenders = 0; using (var fw = new StreamWriter("GHBP_export.txt", true)) { if (distinctSenders.Count > 0) { totalSenders = distinctSenders.Count; foreach (var item in distinctSenders.Keys) { List <Breach> response = null; try { response = client.GetAccountBreaches(item.ToString()).Result; } catch (Exception excp) { //try to wait more if we hit an exception System.Threading.Thread.Sleep(5000); } if (response != null && response.Count > 0) { fw.WriteLine(item); Console.WriteLine(" "); } //To avoid breaking api request limit of 1 request every 1.5 seconds System.Threading.Thread.Sleep(2000); processedSenders++; worker.ReportProgress(processedSenders / totalSenders, "This sender has been pwned: " + item + " - Processed " + processedSenders + " of " + totalSenders + " total senders"); } } } } else { worker.ReportProgress(10000, "No messages found"); } return("Ok"); }