using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Web.Security ;namespace HashPassword
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class HashPasswordForm : System.Windows.Forms.Form
{
private System.Windows.Forms.GroupBox ControlsContainer;
private System.Windows.Forms.Label PasswordLabel;
private System.Windows.Forms.Label ConfirmPasswordLabel;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.RadioButton MD5RadioButton;
private System.Windows.Forms.RadioButton SHA1RadioButton;
private System.Windows.Forms.Button GenerateHashButton;
private System.Windows.Forms.TextBox HashedPasswordTextBox;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
private System.Windows.Forms.TextBox PasswordTextBox;
private System.Windows.Forms.TextBox ConfirmPasswordTextBox;
private System.Windows.Forms.CheckBox ClipboardCopyCheckBox;
//--------------- Added by Asief --------------------
private string HashingAlgorithmName = "MD5" ;
//---------------------------------------------------
public HashPasswordForm()
{
//
// Required for Windows Form Designer support
//
InitializeComponent(); //
// TODO: Add any constructor code after InitializeComponent call
//
} /// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
} #region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.ControlsContainer = new System.Windows.Forms.GroupBox();
this.HashedPasswordTextBox = new System.Windows.Forms.TextBox();
this.GenerateHashButton = new System.Windows.Forms.Button();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.SHA1RadioButton = new System.Windows.Forms.RadioButton();
this.MD5RadioButton = new System.Windows.Forms.RadioButton();
this.ConfirmPasswordTextBox = new System.Windows.Forms.TextBox();
this.PasswordTextBox = new System.Windows.Forms.TextBox();
this.ConfirmPasswordLabel = new System.Windows.Forms.Label();
this.PasswordLabel = new System.Windows.Forms.Label();
this.ClipboardCopyCheckBox = new System.Windows.Forms.CheckBox();
this.ControlsContainer.SuspendLayout();
this.groupBox1.SuspendLayout();
this.SuspendLayout();
//
// ControlsContainer
//
this.ControlsContainer.Controls.AddRange(new System.Windows.Forms.Control[] {
this.ClipboardCopyCheckBox,
this.HashedPasswordTextBox,
this.GenerateHashButton,
this.groupBox1,
this.ConfirmPasswordTextBox,
this.PasswordTextBox,
this.ConfirmPasswordLabel,
this.PasswordLabel});
this.ControlsContainer.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.ControlsContainer.Location = new System.Drawing.Point(8, 0);
this.ControlsContainer.Name = "ControlsContainer";
this.ControlsContainer.Size = new System.Drawing.Size(448, 264);
this.ControlsContainer.TabIndex = 0;
this.ControlsContainer.TabStop = false;
//
// HashedPasswordTextBox
//
this.HashedPasswordTextBox.AutoSize = false;
this.HashedPasswordTextBox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.HashedPasswordTextBox.Location = new System.Drawing.Point(8, 120);
this.HashedPasswordTextBox.Multiline = true;
this.HashedPasswordTextBox.Name = "HashedPasswordTextBox";
this.HashedPasswordTextBox.ReadOnly = true;
this.HashedPasswordTextBox.Size = new System.Drawing.Size(432, 136);
this.HashedPasswordTextBox.TabIndex = 0;
this.HashedPasswordTextBox.TabStop = false;
this.HashedPasswordTextBox.Text = "";
//
// GenerateHashButton
//
this.GenerateHashButton.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.GenerateHashButton.Location = new System.Drawing.Point(256, 88);
this.GenerateHashButton.Name = "GenerateHashButton";
this.GenerateHashButton.Size = new System.Drawing.Size(96, 23);
this.GenerateHashButton.TabIndex = 5;
this.GenerateHashButton.Text = "Hash Password";
this.GenerateHashButton.Click += new System.EventHandler(this.GenerateHashButton_Click);
//
// groupBox1
//
this.groupBox1.Controls.AddRange(new System.Windows.Forms.Control[] {
this.SHA1RadioButton,
this.MD5RadioButton});
this.groupBox1.Location = new System.Drawing.Point(360, 16);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(80, 96);
this.groupBox1.TabIndex = 4;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Algorithm";
//
// SHA1RadioButton
//
this.SHA1RadioButton.Location = new System.Drawing.Point(16, 40);
this.SHA1RadioButton.Name = "SHA1RadioButton";
this.SHA1RadioButton.Size = new System.Drawing.Size(56, 16);
this.SHA1RadioButton.TabIndex = 4;
this.SHA1RadioButton.Text = "SHA1";
this.SHA1RadioButton.CheckedChanged += new System.EventHandler(this.SHA1RadioButton_CheckedChanged);
//
// MD5RadioButton
//
this.MD5RadioButton.Checked = true;
this.MD5RadioButton.Location = new System.Drawing.Point(16, 16);
this.MD5RadioButton.Name = "MD5RadioButton";
this.MD5RadioButton.Size = new System.Drawing.Size(48, 16);
this.MD5RadioButton.TabIndex = 3;
this.MD5RadioButton.TabStop = true;
this.MD5RadioButton.Text = "MD5";
this.MD5RadioButton.CheckedChanged += new System.EventHandler(this.MD5RadioButton_CheckedChanged);
//
// ConfirmPasswordTextBox
//
this.ConfirmPasswordTextBox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.ConfirmPasswordTextBox.Location = new System.Drawing.Point(136, 56);
this.ConfirmPasswordTextBox.Name = "ConfirmPasswordTextBox";
this.ConfirmPasswordTextBox.PasswordChar = '*';
this.ConfirmPasswordTextBox.Size = new System.Drawing.Size(216, 20);
this.ConfirmPasswordTextBox.TabIndex = 2;
this.ConfirmPasswordTextBox.Text = "";
this.ConfirmPasswordTextBox.Enter += new System.EventHandler(this.ConfirmPasswordTextBox_Enter);
//
// PasswordTextBox
//
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Web.Security ;namespace HashPassword
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class HashPasswordForm : System.Windows.Forms.Form
{
private System.Windows.Forms.GroupBox ControlsContainer;
private System.Windows.Forms.Label PasswordLabel;
private System.Windows.Forms.Label ConfirmPasswordLabel;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.RadioButton MD5RadioButton;
private System.Windows.Forms.RadioButton SHA1RadioButton;
private System.Windows.Forms.Button GenerateHashButton;
private System.Windows.Forms.TextBox HashedPasswordTextBox;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
private System.Windows.Forms.TextBox PasswordTextBox;
private System.Windows.Forms.TextBox ConfirmPasswordTextBox;
private System.Windows.Forms.CheckBox ClipboardCopyCheckBox;
//--------------- Added by Asief --------------------
private string HashingAlgorithmName = "MD5" ;
//---------------------------------------------------
public HashPasswordForm()
{
//
// Required for Windows Form Designer support
//
InitializeComponent(); //
// TODO: Add any constructor code after InitializeComponent call
//
} /// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
} #region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.ControlsContainer = new System.Windows.Forms.GroupBox();
this.HashedPasswordTextBox = new System.Windows.Forms.TextBox();
this.GenerateHashButton = new System.Windows.Forms.Button();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.SHA1RadioButton = new System.Windows.Forms.RadioButton();
this.MD5RadioButton = new System.Windows.Forms.RadioButton();
this.ConfirmPasswordTextBox = new System.Windows.Forms.TextBox();
this.PasswordTextBox = new System.Windows.Forms.TextBox();
this.ConfirmPasswordLabel = new System.Windows.Forms.Label();
this.PasswordLabel = new System.Windows.Forms.Label();
this.ClipboardCopyCheckBox = new System.Windows.Forms.CheckBox();
this.ControlsContainer.SuspendLayout();
this.groupBox1.SuspendLayout();
this.SuspendLayout();
//
// ControlsContainer
//
this.ControlsContainer.Controls.AddRange(new System.Windows.Forms.Control[] {
this.ClipboardCopyCheckBox,
this.HashedPasswordTextBox,
this.GenerateHashButton,
this.groupBox1,
this.ConfirmPasswordTextBox,
this.PasswordTextBox,
this.ConfirmPasswordLabel,
this.PasswordLabel});
this.ControlsContainer.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.ControlsContainer.Location = new System.Drawing.Point(8, 0);
this.ControlsContainer.Name = "ControlsContainer";
this.ControlsContainer.Size = new System.Drawing.Size(448, 264);
this.ControlsContainer.TabIndex = 0;
this.ControlsContainer.TabStop = false;
//
// HashedPasswordTextBox
//
this.HashedPasswordTextBox.AutoSize = false;
this.HashedPasswordTextBox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.HashedPasswordTextBox.Location = new System.Drawing.Point(8, 120);
this.HashedPasswordTextBox.Multiline = true;
this.HashedPasswordTextBox.Name = "HashedPasswordTextBox";
this.HashedPasswordTextBox.ReadOnly = true;
this.HashedPasswordTextBox.Size = new System.Drawing.Size(432, 136);
this.HashedPasswordTextBox.TabIndex = 0;
this.HashedPasswordTextBox.TabStop = false;
this.HashedPasswordTextBox.Text = "";
//
// GenerateHashButton
//
this.GenerateHashButton.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.GenerateHashButton.Location = new System.Drawing.Point(256, 88);
this.GenerateHashButton.Name = "GenerateHashButton";
this.GenerateHashButton.Size = new System.Drawing.Size(96, 23);
this.GenerateHashButton.TabIndex = 5;
this.GenerateHashButton.Text = "Hash Password";
this.GenerateHashButton.Click += new System.EventHandler(this.GenerateHashButton_Click);
//
// groupBox1
//
this.groupBox1.Controls.AddRange(new System.Windows.Forms.Control[] {
this.SHA1RadioButton,
this.MD5RadioButton});
this.groupBox1.Location = new System.Drawing.Point(360, 16);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(80, 96);
this.groupBox1.TabIndex = 4;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Algorithm";
//
// SHA1RadioButton
//
this.SHA1RadioButton.Location = new System.Drawing.Point(16, 40);
this.SHA1RadioButton.Name = "SHA1RadioButton";
this.SHA1RadioButton.Size = new System.Drawing.Size(56, 16);
this.SHA1RadioButton.TabIndex = 4;
this.SHA1RadioButton.Text = "SHA1";
this.SHA1RadioButton.CheckedChanged += new System.EventHandler(this.SHA1RadioButton_CheckedChanged);
//
// MD5RadioButton
//
this.MD5RadioButton.Checked = true;
this.MD5RadioButton.Location = new System.Drawing.Point(16, 16);
this.MD5RadioButton.Name = "MD5RadioButton";
this.MD5RadioButton.Size = new System.Drawing.Size(48, 16);
this.MD5RadioButton.TabIndex = 3;
this.MD5RadioButton.TabStop = true;
this.MD5RadioButton.Text = "MD5";
this.MD5RadioButton.CheckedChanged += new System.EventHandler(this.MD5RadioButton_CheckedChanged);
//
// ConfirmPasswordTextBox
//
this.ConfirmPasswordTextBox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.ConfirmPasswordTextBox.Location = new System.Drawing.Point(136, 56);
this.ConfirmPasswordTextBox.Name = "ConfirmPasswordTextBox";
this.ConfirmPasswordTextBox.PasswordChar = '*';
this.ConfirmPasswordTextBox.Size = new System.Drawing.Size(216, 20);
this.ConfirmPasswordTextBox.TabIndex = 2;
this.ConfirmPasswordTextBox.Text = "";
this.ConfirmPasswordTextBox.Enter += new System.EventHandler(this.ConfirmPasswordTextBox_Enter);
//
// PasswordTextBox
//
解决方案 »
- c#winform关于关闭窗体的问题
- B b=new B();A a=b(A,B都是类名)这句话谁帮忙解释下啊?
- winform datagridview插入一行时,怎么检测是否已经存在重复的值
- 求Repeater 如何在显示的列上加链接!
- 彩信上行接收到图片,铃声等附件怎么还原?高分酬谢
- 用c#窗体设计器设计的界面,保存后,再打开,就乱掉了,代码丢失
- 明明引用里有,为何水晶报表部署时还报:找不到crystalDecision.windows.form.dll的依赖项
- 谁用过DotRas,来调用plike,请问这样可以连接上SSH么?
- 关于类型转换(在线等待)
- listbox的问题
- C#开发的windows程序中的ListView怎么按列排序呀?
- 請問如何copy整個文件夾
this.PasswordTextBox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.PasswordTextBox.Location = new System.Drawing.Point(136, 24);
this.PasswordTextBox.Name = "PasswordTextBox";
this.PasswordTextBox.PasswordChar = '*';
this.PasswordTextBox.Size = new System.Drawing.Size(216, 20);
this.PasswordTextBox.TabIndex = 1;
this.PasswordTextBox.Text = "";
this.PasswordTextBox.Enter += new System.EventHandler(this.PasswordTextBox_Enter);
//
// ConfirmPasswordLabel
//
this.ConfirmPasswordLabel.Location = new System.Drawing.Point(16, 56);
this.ConfirmPasswordLabel.Name = "ConfirmPasswordLabel";
this.ConfirmPasswordLabel.Size = new System.Drawing.Size(112, 16);
this.ConfirmPasswordLabel.TabIndex = 0;
this.ConfirmPasswordLabel.Text = "Confirm Password";
//
// PasswordLabel
//
this.PasswordLabel.Location = new System.Drawing.Point(16, 24);
this.PasswordLabel.Name = "PasswordLabel";
this.PasswordLabel.Size = new System.Drawing.Size(112, 16);
this.PasswordLabel.TabIndex = 0;
this.PasswordLabel.Text = "Password";
//
// ClipboardCopyCheckBox
//
this.ClipboardCopyCheckBox.Checked = true;
this.ClipboardCopyCheckBox.CheckState = System.Windows.Forms.CheckState.Checked;
this.ClipboardCopyCheckBox.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.ClipboardCopyCheckBox.Location = new System.Drawing.Point(8, 96);
this.ClipboardCopyCheckBox.Name = "ClipboardCopyCheckBox";
this.ClipboardCopyCheckBox.Size = new System.Drawing.Size(208, 16);
this.ClipboardCopyCheckBox.TabIndex = 6;
this.ClipboardCopyCheckBox.Text = "Copy hashed password to clipboard";
//
// HashPasswordForm
//
this.AcceptButton = this.GenerateHashButton;
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.BackColor = System.Drawing.SystemColors.ActiveBorder;
this.ClientSize = new System.Drawing.Size(464, 273);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.ControlsContainer});
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.MaximizeBox = false;
this.Name = "HashPasswordForm";
this.Text = "Hash Password Application";
this.ControlsContainer.ResumeLayout(false);
this.groupBox1.ResumeLayout(false);
this.ResumeLayout(false); }
#endregion /// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new HashPasswordForm());
} private void MD5RadioButton_CheckedChanged(object sender, System.EventArgs e)
{
if (MD5RadioButton.Checked)
HashingAlgorithmName = "MD5" ; } private void SHA1RadioButton_CheckedChanged(object sender, System.EventArgs e)
{
if (SHA1RadioButton.Checked)
HashingAlgorithmName = "SHA1" ;
} private void GenerateHashButton_Click(object sender, System.EventArgs e)
{
const string EmptyPasswordFieldsMessage = "Password Fields are required" ;
const string PasswordsMismatchMessage = "Passwords should match" ;
const string TrailingLeadingSpacesMessage = "Password should not be trailed or lead by spaces" ; HashedPasswordTextBox.Text = "";
if (PasswordTextBox.Text.Trim() == String.Empty
|| ConfirmPasswordTextBox.Text.Trim() == String.Empty )
{
MessageBox.Show( EmptyPasswordFieldsMessage );
PasswordTextBox.SelectAll();
PasswordTextBox.Focus();
return; } if (PasswordTextBox.Text.StartsWith(" ") || PasswordTextBox.Text.EndsWith(" "))
{
MessageBox.Show( TrailingLeadingSpacesMessage );
PasswordTextBox.SelectAll();
PasswordTextBox.Focus();
return; } if (PasswordTextBox.Text != ConfirmPasswordTextBox.Text)
{
MessageBox.Show( PasswordsMismatchMessage );
PasswordTextBox.SelectAll();
PasswordTextBox.Focus();
return; } HashedPasswordTextBox.Text = FormsAuthentication.HashPasswordForStoringInConfigFile(PasswordTextBox.Text, HashingAlgorithmName);
if (ClipboardCopyCheckBox.Checked)
Clipboard.SetDataObject( HashedPasswordTextBox.Text,false); return; } private void PasswordTextBox_Enter(object sender, System.EventArgs e)
{
PasswordTextBox.SelectAll();
} private void ConfirmPasswordTextBox_Enter(object sender, System.EventArgs e)
{
ConfirmPasswordTextBox.SelectAll();
}
}
}