using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using PasswordStrengthControlLib;
namespace PasswordStrengthDemo
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
textBox2_TextChanged(null, null);
propertyGrid1.SelectedObject = passwordStrengthControl12;
propertyGrid1.PropertyValueChanged += new PropertyValueChangedEventHandler(propertyGrid1_PropertyValueChanged);
}
void propertyGrid1_PropertyValueChanged(object s, PropertyValueChangedEventArgs e)
{
passwordStrengthControl12 = (PasswordStrengthControl)propertyGrid1.SelectedObject;
passwordStrengthControl12.Invalidate();
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
int x = PasswordStregthManager.Instance.GetPasswordScore(textBox1.Text, textBox2.Text);
string str = PasswordStregthManager.Instance.GetPasswordStrength(textBox1.Text, textBox2.Text);
Color col = PasswordStregthManager.Instance.GetPasswordColor(textBox1.Text, textBox2.Text);
this.SetPasswordControls(this.passwordStrengthControl1 , x,str, Color.Black ,col);
this.SetPasswordControls(this.passwordStrengthControl2, x, str, Color.Black, col);
this.SetPasswordControls(this.passwordStrengthControl3, x, str, Color.Black, col);
this.SetPasswordControls(this.passwordStrengthControl4, x, str, Color.Black, col);
this.SetPasswordControls(this.passwordStrengthControl5, x, str, Color.Black, col);
this.SetPasswordControls(this.passwordStrengthControl6, x, str, Color.Black, col);
this.SetPasswordControls(this.passwordStrengthControl7, x, str, Color.Black, col);
this.SetPasswordControls(this.passwordStrengthControl8, x, str, Color.Black, col);
this.SetPasswordControls(this.passwordStrengthControl9, x, str, Color.Black, col);
this.SetPasswordControls(this.passwordStrengthControl10, x, str, Color.Black, col);
this.SetPasswordControls(this.passwordStrengthControl11, x, str, Color.Black, col);
this.SetPasswordControls(this.passwordStrengthControl2, x, str, this.passwordStrengthControl2.ForeColor, this.passwordStrengthControl2.SolidColor);
}
private void SetPasswordControls(PasswordStrengthControl cont , int s , string text , Color f , Color b)
{
cont.Strength = s;
cont.SolidColor = b;
cont.ForeColor = f;
cont.StrengthText = text;
}
private void Form1_Load(object sender, EventArgs e)
{
textBox2.Focus();
}
private void passwordStrengthControl1_StrengtChangedEventHandler(object sender, StrengthChangedEventArgs e)
{
label1.Text = e.Text + " ( " + e.Level + " / {" + passwordStrengthControl1.MaxStrength + "})";
}
}
}