| ||||||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||
IntroductionThis article is about a Password Strength control, which can be used in password dialogs and login windows in Windows based .NET applications. If you want, you can use it as a progress bar control as well. This control can be shaped to different styles and can be extended, if needed. BackgroundCustom control design is one of the fascinating features given by the .NET framework to control authors. Using inheritance, we can extend the behavior or the look and feel of preexisting Windows Forms controls. In addition, because of the flexibility given to authors, they can give designers good design time experience using property grids and other means. There are lots of controls with similar features in the web using the power of JavaScript and AJAX, but I was not able to find such a control for Windows based applications. Because of this, I decided to create this control, which I believe has very good value. You can use this control mainly in Change Password windows and in Login dialog boxes to show the strength of the input password. Using the security policy of the company, given a password, you can decide a mark for the strength of that password. In my demo application, I have used a one password strength algorithm to show the power of this control. In addition, you can divide the entire strength range in to several segments and name those as you wish. In my demo application, I have used ranges like Short, Weak, Good, and Strong. What are the styles available in this control? Using the
Using the same styles, you can change the control behavior and look and
feel to a segmented mode using the To change the alignment of the text, you can use the
Control ImplementationThe Password Strength control is an extension of the
The main implementation is in the In the Region region = new Region();
Rectangle segmentRect = new Rectangle(InnerRectangle.Left, InnerRectangle.Top,
swidth, InnerRectangle.Height);
for (int i = 0; i < segmentNumber; i++) {
region.Union(segmentRect);
segmentRect.Offset(swidth + gap, 0);
}
I used this code snippet to create a segmented region just like a
scale. Then, using the Other important implantations are the LinearGradientBrush gradientBrush = new LinearGradientBrush(
new Point(rc.X, rc.Y),
new Point(rc.X + rc.Width, rc.Y),
this.gradientStratColor,
this.gradientEndColor);
I used the In the LinearGradientBrush gradientBrush = new LinearGradientBrush(
new Point(rc.X, rc.Y),
new Point(rc.X, rc.Y + rc.Height),
this.gradientStratColor,
this.gradientEndColor);
ColorBlend colorBlend = new ColorBlend(3);
colorBlend.Colors = new Color[] { this.gradientEndColor,
this.gradientStratColor, this.gradientEndColor };
colorBlend.Positions = new float[] { 0, (float)0.4, 1 };
gradientBrush.InterpolationColors = colorBlend;
When designing a control, we have to consider the properties we are
going to expose to the propertygrid and other external entities. Using the
attributes given by the
Apart from these, I have used: [ToolboxItem(true)]
[ToolboxBitmap(typeof(ProgressBar))]
[Description ("Password Strength Control with different styles.")]
Attributes which will be used by the Toolbox when you add this to the VS2005 Toolbox:
I created a new event called If you want to extend this control, you can do that by easily overriding the existing method implementations in any way suitable. Discussions and Feedback2 messages have been posted for this article. Visit http://www.codeproject.com/KB/edit/PasswordStrengh.aspx to post and view comments on this article, or click here to get a print view with messages.
| ||||||||||||||||||||||||||||||||||||||||||