?? form1.cs
字號:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Web.Security;
using System.Data.SqlClient;
namespace Encryption
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
internal System.Windows.Forms.TextBox txtEncryptedPassword;
internal System.Windows.Forms.Label Label2;
internal System.Windows.Forms.Label Label1;
internal System.Windows.Forms.TextBox txtPassword;
internal System.Windows.Forms.Button btnEncrypt;
internal System.Windows.Forms.Label label3;
internal System.Windows.Forms.Label label4;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// 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()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
this.txtEncryptedPassword = new System.Windows.Forms.TextBox();
this.Label2 = new System.Windows.Forms.Label();
this.Label1 = new System.Windows.Forms.Label();
this.txtPassword = new System.Windows.Forms.TextBox();
this.btnEncrypt = new System.Windows.Forms.Button();
this.label3 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// txtEncryptedPassword
//
this.txtEncryptedPassword.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.txtEncryptedPassword.Location = new System.Drawing.Point(232, 64);
this.txtEncryptedPassword.Name = "txtEncryptedPassword";
this.txtEncryptedPassword.Size = new System.Drawing.Size(472, 20);
this.txtEncryptedPassword.TabIndex = 27;
this.txtEncryptedPassword.Text = "";
//
// Label2
//
this.Label2.Font = new System.Drawing.Font("Tahoma", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.Label2.Location = new System.Drawing.Point(-108, 175);
this.Label2.Name = "Label2";
this.Label2.Size = new System.Drawing.Size(128, 23);
this.Label2.TabIndex = 26;
this.Label2.Text = "Encrypted Password";
//
// Label1
//
this.Label1.Font = new System.Drawing.Font("Tahoma", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.Label1.Location = new System.Drawing.Point(-100, 135);
this.Label1.Name = "Label1";
this.Label1.Size = new System.Drawing.Size(112, 23);
this.Label1.TabIndex = 25;
this.Label1.Text = "Clear Password:";
//
// txtPassword
//
this.txtPassword.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.txtPassword.Location = new System.Drawing.Point(232, 32);
this.txtPassword.Name = "txtPassword";
this.txtPassword.Size = new System.Drawing.Size(184, 20);
this.txtPassword.TabIndex = 24;
this.txtPassword.Text = "";
//
// btnEncrypt
//
this.btnEncrypt.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnEncrypt.Image = ((System.Drawing.Image)(resources.GetObject("btnEncrypt.Image")));
this.btnEncrypt.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
this.btnEncrypt.Location = new System.Drawing.Point(336, 104);
this.btnEncrypt.Name = "btnEncrypt";
this.btnEncrypt.TabIndex = 23;
this.btnEncrypt.Text = "Encrypt";
this.btnEncrypt.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
this.btnEncrypt.Click += new System.EventHandler(this.btnEncrypt_Click);
//
// label3
//
this.label3.Font = new System.Drawing.Font("Tahoma", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.label3.Location = new System.Drawing.Point(32, 72);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(184, 23);
this.label3.TabIndex = 29;
this.label3.Text = "Encrypted Password with MD5:";
//
// label4
//
this.label4.Font = new System.Drawing.Font("Tahoma", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.label4.Location = new System.Drawing.Point(104, 40);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(104, 23);
this.label4.TabIndex = 28;
this.label4.Text = "Clear Password:";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(728, 141);
this.Controls.Add(this.label3);
this.Controls.Add(this.label4);
this.Controls.Add(this.txtEncryptedPassword);
this.Controls.Add(this.Label2);
this.Controls.Add(this.Label1);
this.Controls.Add(this.txtPassword);
this.Controls.Add(this.btnEncrypt);
this.Name = "Form1";
this.Text = "Encryption";
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void btnEncrypt_Click(object sender, System.EventArgs e)
{
//Encrypting password. Applying SHA1 Encryption Algo
this.txtEncryptedPassword.Text = EncryptingPassword();
updatePasswordInDB("Server=Fahad; database=TestDB; uid=sa; pwd=sqladmin");
}
public string EncryptingPassword()
{
//Return Encrypted Password
return FormsAuthentication.HashPasswordForStoringInConfigFile(this.txtPassword.Text.Trim(), "MD5");
}
public void updatePasswordInDB(string connectionString)
{
SqlConnection objConn= new SqlConnection(connectionString);
objConn.Open();
SqlCommand objcmd = new SqlCommand("update TestEncryption set password = '" + this.txtEncryptedPassword.Text.Trim() + "' where name = 'Qamar'", objConn);
objcmd.ExecuteNonQuery();
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -