Click here to Skip to main content
12,816,032 members (38,923 online)
Click here to Skip to main content
Add your own
alternative version


16 bookmarked
Posted 24 Jun 2005

Complete Users' Password Administration for .NET

, 24 Jun 2005
Rate this:
Please Sign up or sign in to vote.
This article creates a complete suite to manage users and users' passwords. The application saves and loads all the data using an XML file and MD5 encryption.

Sample Image


I have looked for a simple way to save user data to an XML file. All the solutions I have found used XML serialization (=> not so simple). So I have decided to create my own application. The data in the XML file must be encoded for security reason.

The following subjects are discussed in this article:

  1. Encode string using MD5 encoding.
  2. Load all user database from the XML file to the application.
  3. Save all user database to an XML file.
  4. Look for an object in an ArrayList.


To change the Desktop background, the application needs to use the WinAPI SystemParametersInfo and supply it with the desired image parameters. The only problem is that the API accepts only BMP image type. My solution was to create a BMP from each JPG or JPEG file in the directory.

Using the code

  1. Encode string using MD5 encoding:

    In order to do the encoding, this application creates a MD5 Encoding object. Using StringBuilder, the string is then converted into an array of bytes and converted back to string after the MD5 encoding.

    MD5 md5serv = MD5CryptoServiceProvider.Create();
    byte[] hash;
    StringBuilder stringbuff = new StringBuilder();
    ASCIIEncoding asciienc = new ASCIIEncoding();
    // convert string into array of bytes
    byte[] buffer = asciienc.GetBytes(raw);
    // Comupte the hash for the string
    hash = md5serv.ComputeHash(buffer);
    foreach (byte b in hash) { stringbuff.Append(b.ToString("x2")); }
    return stringbuff.ToString();
  2. Load all user database from the XML file to the application:

    The method used reads the XML file into a XmlTextReader. Then it searches for new XML elements. For each element, the method extracts its attributes. Attributes are extracted from reader.Value.

    while (reader.Read()) {
        if (reader.NodeType == XmlNodeType.Element) {
            elementName = reader.Name;
            while (reader.MoveToNextAttribute()) {
                if (reader.Name == "Password")
                    myUser.Password = reader.Value;
  3. Save all user database to an XML file:

    Save all user database to an XML file from the application. The method used here uses the XmlTextWriter. It saves all the users to a new XML file. First of all, the XML options must be set - like formatting and indentation. Then it writes the start element. After that, for each user, the method adds its attributes (XML attributes) to the user name (XML element).

    XmlTextWriter writer = new XmlTextWriter(strPath + "\\users.xml", null);
    writer.Formatting = Formatting.Indented;
    writer.Indentation = 4;
    foreach (User myUser in myAL) {
        for each user (myUser.UserName);
        writer.WriteAttributeString("Password", myUser.Password);
        writer.WriteAttributeString("Previliage", myUser.Previliage);
  4. Remove an object from an ArrayList:

    If you want to delete an object from an ArrayList, you don't need any index. All you need is to find the correct pointer and delete it.

    foreach (User myUser in myAL) {
        if (myUser.UserName == (string)listBoxUser.SelectedItem)




This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

arbel kfir
Web Developer
Israel Israel
partying, girls, partying, girls

and a bit of c#

homepage : http:\\

You may also be interested in...


Comments and Discussions

GeneralNeeds some work Pin
Frank McCown7-Oct-05 2:06
sussFrank McCown7-Oct-05 2:06 
GeneralMr. Webster "writ" a mighty fine dictionary Pin
fwsouthern24-Jun-05 10:52
memberfwsouthern24-Jun-05 10:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170308.1 | Last Updated 24 Jun 2005
Article Copyright 2005 by arbel kfir
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid