Advertisement
Guest User

Untitled

a guest
Feb 13th, 2017
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.73 KB | None | 0 0
  1. class OTP:ITwoFactorCodeProvider
  2. {
  3.  
  4. public string otpAuth = string.Empty;
  5. private double m_mailretentionSeconds;
  6. private string m_popServer;
  7. private int m_popPort;
  8. private string m_popUserName;
  9. private string m_popPassword;
  10.  
  11.  
  12. public OTP(double mailretentionSeconds, string popServer, int popPort, string popUserName, string popPassword)
  13. {
  14. m_mailretentionSeconds = mailretentionSeconds;
  15. m_popServer = popServer;
  16. m_popPort = popPort;
  17. m_popUserName = popUserName;
  18. m_popPassword = popPassword;
  19. }
  20. public async Task<string> GetTwoFactorCodeAsync()
  21. {
  22. await GetMail();
  23. return await Task.FromResult<string>(otpAuth);
  24.  
  25. throw new NotImplementedException();
  26. }
  27.  
  28. public async Task GetMail()
  29. {
  30. List<Mail> mailList = new List<Mail>();
  31. Regex regex = new Regex(@"y=\([0-9]\)\([0-9]\)(\s|)\+(\s+|)[0-9]");
  32. Match match = regex.Match("y=(4)(5)+6");
  33. bool deleteMails = true;
  34.  
  35. while (otpAuth == string.Empty)
  36. {
  37. while (mailList.Count < 1)
  38. {
  39. MailProvider mailProv_get = new MailProvider(m_popServer, m_popPort, m_popUserName, m_popPassword);
  40. mailList = mailProv_get.GetMails(deleteMails);
  41. mailList.Reverse();
  42. await Task.Delay(2000);
  43. }
  44. foreach (Mail mail in mailList)
  45. {
  46. DateTime dateMail = Convert.ToDateTime(mail.Date);
  47. if (mail.SenderMail.Contains("ea.com") == true && DateTime.Now < dateMail.AddSeconds(m_mailretentionSeconds))
  48. {
  49. otpAuth = Convert.ToString(Convert.ToString(ConvertToInt(mail.Title)));
  50. }
  51. }
  52. }
  53. mailList.Clear();
  54. MailProvider mailProv_delete = new MailProvider(m_popServer, m_popPort, m_popUserName, m_popPassword);
  55. mailList = mailProv_delete.GetMails(deleteMails);
  56. }
  57.  
  58. public async Task DeleteMail()
  59. {
  60. await Task.Delay(1);
  61.  
  62. bool deleteMails = true;
  63. List<Mail> mailList = new List<Mail>();
  64. MailProvider mailProv_get = new MailProvider(m_popServer, m_popPort, m_popUserName, m_popPassword);
  65. mailList = mailProv_get.GetMails(deleteMails);
  66. }
  67.  
  68. public static string ConvertToInt(String input)
  69. {
  70. Match match = Regex.Match(input, "-?[0-9]+");
  71.  
  72. if (match.Success)
  73. {
  74. return match.Value;
  75. }
  76. return match.Value;
  77. }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement