Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class OTP:ITwoFactorCodeProvider
- {
- public string otpAuth = string.Empty;
- private double m_mailretentionSeconds;
- private string m_popServer;
- private int m_popPort;
- private string m_popUserName;
- private string m_popPassword;
- public OTP(double mailretentionSeconds, string popServer, int popPort, string popUserName, string popPassword)
- {
- m_mailretentionSeconds = mailretentionSeconds;
- m_popServer = popServer;
- m_popPort = popPort;
- m_popUserName = popUserName;
- m_popPassword = popPassword;
- }
- public async Task<string> GetTwoFactorCodeAsync()
- {
- await GetMail();
- return await Task.FromResult<string>(otpAuth);
- throw new NotImplementedException();
- }
- public async Task GetMail()
- {
- List<Mail> mailList = new List<Mail>();
- Regex regex = new Regex(@"y=\([0-9]\)\([0-9]\)(\s|)\+(\s+|)[0-9]");
- Match match = regex.Match("y=(4)(5)+6");
- bool deleteMails = true;
- while (otpAuth == string.Empty)
- {
- while (mailList.Count < 1)
- {
- MailProvider mailProv_get = new MailProvider(m_popServer, m_popPort, m_popUserName, m_popPassword);
- mailList = mailProv_get.GetMails(deleteMails);
- mailList.Reverse();
- await Task.Delay(2000);
- }
- foreach (Mail mail in mailList)
- {
- DateTime dateMail = Convert.ToDateTime(mail.Date);
- if (mail.SenderMail.Contains("ea.com") == true && DateTime.Now < dateMail.AddSeconds(m_mailretentionSeconds))
- {
- otpAuth = Convert.ToString(Convert.ToString(ConvertToInt(mail.Title)));
- }
- }
- }
- mailList.Clear();
- MailProvider mailProv_delete = new MailProvider(m_popServer, m_popPort, m_popUserName, m_popPassword);
- mailList = mailProv_delete.GetMails(deleteMails);
- }
- public async Task DeleteMail()
- {
- await Task.Delay(1);
- bool deleteMails = true;
- List<Mail> mailList = new List<Mail>();
- MailProvider mailProv_get = new MailProvider(m_popServer, m_popPort, m_popUserName, m_popPassword);
- mailList = mailProv_get.GetMails(deleteMails);
- }
- public static string ConvertToInt(String input)
- {
- Match match = Regex.Match(input, "-?[0-9]+");
- if (match.Success)
- {
- return match.Value;
- }
- return match.Value;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement