Click here to Skip to main content
15,885,890 members
Articles / Mobile Apps

Windows Mobile Password Safe

Rate me:
Please Sign up or sign in to vote.
4.87/5 (58 votes)
12 Jan 2009CPOL16 min read 159.5K   3.1K   139  
A password safe with a touch screen UI introducing Fluid Controls.
using System;

using System.Collections.Generic;
using System.Text;
using Fluid.Controls;
using PasswordSafe.Xml;
using System.Drawing;
using System.Windows.Forms;
using PasswordSafe.Classes;

namespace PasswordSafe.Templates
{
    public class PasswordTemplate : FluidTemplate
    {
        protected override void InitControl()
        {
            base.InitControl();
            this.Bounds = new Rectangle(0, 0, 240, 64);
            FluidLabel l;

            //l = new FluidLabel("", 3, 0, 228, 20);
            //l.LineAlignment = StringAlignment.Near;
            //            l.Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top;
            l = new FluidLabel("", 3, 0, 228, 64 - 3);
            l.Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top | AnchorStyles.Bottom;
            l.LineAlignment = StringAlignment.Center;
            l.Font = new Font(FontFamily.GenericSansSerif, 10f, FontStyle.Bold);
            nameLabel = l;
            Controls.Add(l);

            l = new FluidLabel("", 8, 62 - 12, 224, 12);
            l.LineAlignment = StringAlignment.Far;
            l.Alignment = StringAlignment.Far;
            l.Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Bottom;
            l.Font = new Font(FontFamily.GenericSansSerif, 6f, FontStyle.Regular);
            l.ForeColor = Theme.Current.ListSecondaryForeColor;
            secondaryLabel = l;
            Controls.Add(l);
        }

        private FluidLabel nameLabel;
        private FluidLabel secondaryLabel;

        protected override void OnBindValue(object value)
        {
            PasswordData password = value as PasswordData;
            if (password != null)
            {
                nameLabel.Text = password.Name;
                secondaryLabel.Text = GetSecondaryLabel(password);
            }
            else
            {
                nameLabel.Text = "";
                secondaryLabel.Text = "";
            }
        }


        /// <summary>
        /// Get the secondary label from a password.
        /// User is prefered, but if emtpy, select the next field that is not empty and which is not a password.
        /// </summary>
        /// <param name="password">The PasswordData from which to retreive the secondary label.</param>
        /// <returns>A string, otherwise String.Empty.</returns>
        private string GetSecondaryLabel(PasswordData password)
        {
            if (!string.IsNullOrEmpty(password.User)) return password.User;

            bool first = true;
            foreach (string name in password.Values.AllKeys)
            {
                if (first)
                {
                    first = false;
                    continue;
                }
                string value = password.Values[name];
                if (value == password.Password) continue;
                if (!string.IsNullOrEmpty(value))
                {
                    return value;
                }
            }
            return string.Empty;
        }

        protected override void OnItemUpdate(object value)
        {
            PasswordsListBox lb = Parent as PasswordsListBox;
            secondaryLabel.ForeColor = lb.SelectedItemIndex == this.ItemIndex ? Theme.Current.ListSecondarySelectedForeColor : Theme.Current.ListSecondaryForeColor;
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

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


Written By
Software Developer (Senior)
Germany Germany
MCPD
Enterprise Application Developer 3.5
Windows Developer 3.5
.ASP.NET Developer 3.5
.NET 2.0 Windows Developer
.NET 2.0 Web Developer
.NET 2.0 Enterprise Application Developer


MCTS
.NET 3.5 Windows Forms Applications
.NET 3.5 ASP.NET Applications
.NET 3.5, ADO.NET Application Development
.NET 3.5 WCF
.NET 3.5 WPF
.NET 3.5 WF
Microsoft SQL Server 2008, Database Development
.NET 2.0 Windows Applications
.NET 2.0 Web Applications
.NET 2.0 Distributed Applications
SQL Server 2005
Sharepoint Services 3.0 Application Development
Windows Vista Client Configuration

Comments and Discussions