Click here to Skip to main content
16,020,182 members
Articles / Desktop Programming / Windows Forms

Password Manager and Web Form Filler

Rate me:
Please Sign up or sign in to vote.
2.00/5 (1 vote)
26 Jul 2007CPOL3 min read 23.5K   649   17  
How to build a simple user account manager which can automatically login to websites.

Screenshot - enigma.gif

Introduction

Lately, I've been travelling a lot and I have to use my email and other accounts via web forms. To keep track of all accounts, I keep a little black book with me, but still need to enter the data every time I log in. I searched the web for password fillers and thought they were all so heavy-weight and packed with lots of features while I only needed a password manager that could send keystrokes to a WebForm. So, I did what every programmer does in that case: built it myself.

You can start Enigma as a normal Windows application, or with a command-line parameter which starts an account and closes Enigma.

  • enigma.exe
  • enigma.exe "testaccount"

Using the Code

This project is pretty straightforward. It does:

  • Reads an XML file with account info;
  • Fills a listview with this data;
  • On a double-click, starts IE and sends keystrokes with your account info to it;
  • Accepts a command line argument.

First, let's get the account info from enigma.xml. We declare this function:

C#
public static object DeSerialize(string fileName, Type type)
{
    using (FileStream input = new FileStream(fileName, FileMode.Open))
    {
        XmlSerializer sr = new XmlSerializer(type);
        object o = sr.Deserialize(input);
        input.Close();
        return o;
    }
}

And, call it with:

C#
accountmanager = (AccountManager)Serializer.DeSerialize(_XMLPath, 
                                 typeof(AccountManager));

This is a great way to deserialize (and serialize) any object in your project. As long as you use serializable types, you can store and retrieve your complete application status in it.

The list of accounts is displayed in a listview. If an account is double-clicked, its info is retrieved from the account collection. In .NET 2.0, I used to loop through a collection to find an item. In this project, I've used some LINQ to do that. It was a perfect way to use LINQ for the first time.

C#
public Account GetAccount(string accountname)
{
    return accountlist.First(x => x.Name.ToLower() == accountname.ToLower());
}

IE is started like this:

C#
Process browser = Process.Start(@"C:\Program Files\Internet Explorer\iexplore.exe", 
                                accountmanager.selectedaccount.Url);

And two timers are started:

C#
timerStartApp.Enabled = true;
timerCloseEnigma.Enabled = true;

timerStartApp starts filling the web form, and timerCloseEnigma closes Enigma if it's started as an app with command-line arguments. On timerStartApp_Tick, the login info is parsed to an array of strings. These array items hold the data for a single web form field. After sending an array item, it's followed by a TAB, and at the end, with an ENTER.

C#
void timerStartApp_Tick(object sender, EventArgs e)
{
    timerStartApp.Enabled = false;
    string[] tabs = accountmanager.selectedaccount.KeyStrokes.Split('|');
    for (int i = 0; i < tabs.Length; i++)
    {
        for (int j = 0; j < tabs[i].Length; j++)
        {
            System.Windows.Forms.SendKeys.Send(tabs[i][j].ToString());
            Application.DoEvents();
        }
        if (i < tabs.Length - 1)
        {
            System.Windows.Forms.SendKeys.Send("{TAB}");
            Application.DoEvents();
        }
    }
    System.Windows.Forms.SendKeys.Send("{ENTER}");
    Application.DoEvents();
}

And, that's pretty much all of it. You can send a complete string to SendKeys.Send(), but I've experienced some problems with that method. So I chose to loop through the string and send the characters one by one.

Points of Interest

I stopped coding once it worked for me, but I guess there are a few issues to be worked out if you want to use it:

  • It currently only works with IE (but that's easily helped if you change the line "C:\Program Files\Internet Explorer\iexplore.exe").
  • It sometimes sends multiple keystrokes where it only should send one. If you know a solution to that problem, please let me know at enigma@toverstudio.nl.
  • The target web form needs to have the focus on the first form field.
  • Account info is stored unencrypted

Be careful with your account info! If a new application starts 'while using Enigma' and gets the focus, Enigma will send your account info to it. This can be a problem if that application is a chat program like Messenger :-)

Orcas version

The demo project failed when I updated to Orcas Beta 2. I had to recompile the executable, and then it worked.

History

  • 26 July 2007: First version.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
Netherlands Netherlands
Loek van den Ouweland is a freelance Web Developer from The Netherlands.

Comments and Discussions

 
-- There are no messages in this forum --