Extracting Confirmation Code

knockoutlocal

Junior Member
Joined
Jun 5, 2012
Messages
170
Reaction score
72
I've built a selenium bot that submits business information to different citation directories. I have captcha solving and email confirmations built in, however, I'm having trouble with some directories that send you an e-mail with a temporary then make you click a confirmation link and type the password in.

Finding the confirmation link is not problem, but I can't figure out how to extract the confirmation code that gets sent to me.

The e-mails will have something that says "Your temporary password is: xxxxxxxxxxxx Click on this link: http://xxxxxxxxxx and log in."

Any suggestions on how to extract the temporary password out?
Background:
-Program uses:
-seleneium framework
-OpenPOP for e-mail
-Written in C# Winforms

Any help would be appreciated.
 
If the emails are in html format you can use HTMLAgilityPack to get the password.
Otherwise I would use regular expressions to find the password
 
Although it is not my language, but I will surely use regex for doing this if I was you. try searching at regexlib.com
 
I've been trying to find a solution that doesn't involve reading hieroglyphics(Regex) but I guess I better man up and start learning it.

Thanks for the suggestions.
 
Code:
public string GetConfirmationCode(string input)
{
       Match match1 = Regex.Match(input, "is: (.*?) Click");
       return match1.Value.Replace("is: ","").Replace(" Click","");
}

use Regex to extract it. Find the pattern and (.*?) will extract everything between those two patterns. Then replace the junk with "" or string.Empty

make sure to refrence: using System.Text.RegularExpressions
Hope this helps.
 
Last edited:
here you can see it in action:
Code:
using System;
using System.Text.RegularExpressions;


namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            string input = "The e-mails will have something that says Your temporary password is: xxxxxxxxxxxx Click on this link: http://google.com and log in.";
            Console.WriteLine(GetConfirmationCode(input));
            Console.ReadLine();
        }


        private static string GetConfirmationCode(string input)
        {
            Match match1 = Regex.Match(input, "is: (.*?) Click");
            return match1.Value.Replace("is: ", "").Replace(" Click", "");
        }
    }
}

// prints xxxxxxxxxxxx
View attachment 48852
 
here you can see it in action:
Code:
using System;
using System.Text.RegularExpressions;


namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            string input = "The e-mails will have something that says Your temporary password is: xxxxxxxxxxxx Click on this link: http://google.com and log in.";
            Console.WriteLine(GetConfirmationCode(input));
            Console.ReadLine();
        }


        private static string GetConfirmationCode(string input)
        {
            Match match1 = Regex.Match(input, "is: (.*?) Click");
            return match1.Value.Replace("is: ", "").Replace(" Click", "");
        }
    }
}

// prints xxxxxxxxxxxx

A little cleaner would be to skip the string replacing and just return the captured text. So all your code, but with this for the return statement...

Code:
return match1.Groups[1].Value;

That will give more power when you get into increasingly complex regular expressions, too.
 
I ended up using html agility pack (I solved it before I saw the responses above). Thank you all for your help
 
Back
Top