gimme ur mail id.
I have whole code but gimme ur mail id but id wnat to use this then u can.
using System;
using System.ComponentModel;
using System.Security.Cryptography;
using System.Text;
using System.Windows.Forms;
namespace pinky
{
///
/// LoginControl is a free .NET login control with cryptography support.
///
public class LoginControl : System.Windows.Forms.UserControl
{
///
/// Raised after a successful Login.
///
public event System.EventHandler Successful;
///
/// Raised after a failed Login.
///
public event System.EventHandler Failed;
///
/// Raised after the User clicked on Login. Use this event to monitor LoginControl.
///
///
This sample shows how to use Ready.
///
/// private void OnEventReady(object sender, System.EventArgs e)
/// {
/// MessageBox.Show("Username: " + loginControl1.Username + "\nPassword: " + loginControl1.Password,"LoginControl");
/// }
///
///
public event System.EventHandler Ready;
private bool bCheck = true;
private bool bHash= true;
private string theUsername;
private string thePassword;
private string tmpU;
private string tmpP;
private string ErrMsg = "Please enter the correct Username / Password combination!";
private System.Windows.Forms.Button bLogin;
private System.Windows.Forms.Label lPassword;
private System.Windows.Forms.Label lUsername;
private System.Windows.Forms.TextBox tbPassword;
private System.Windows.Forms.Label lHeader;
private System.Windows.Forms.Label lText;
private System.Windows.Forms.PictureBox pbImage;
private System.Windows.Forms.TextBox tbUsername;
private System.Windows.Forms.Panel pHeader;
private System.Windows.Forms.ErrorProvider errorProvider;
///
/// Required designer variable.
///
private System.ComponentModel.Container components = null;
///
/// The public Initializer. Nothing happening here.
///
public LoginControl()
{
InitializeComponent();
}
///
/// Clean up any resources being used.
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Component Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(LoginControl));
this.bLogin = new System.Windows.Forms.Button();
this.lPassword = new System.Windows.Forms.Label();
this.lUsername = new System.Windows.Forms.Label();
this.tbPassword = new System.Windows.Forms.TextBox();
this.pHeader = new System.Windows.Forms.Panel();
this.lHeader = new System.Windows.Forms.Label();
this.lText = new System.Windows.Forms.Label();
this.pbImage = new System.Windows.Forms.PictureBox();
this.tbUsername = new System.Windows.Forms.TextBox();
this.errorProvider = new System.Windows.Forms.ErrorProvider();
this.pHeader.SuspendLayout();
this.SuspendLayout();
//
// bLogin
//
this.bLogin.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
this.bLogin.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.bLogin.Location = new System.Drawing.Point(330, 245);
this.bLogin.Name = "bLogin";
this.bLogin.Size = new System.Drawing.Size(70, 20);
this.bLogin.TabIndex = 9;
this.bLogin.Text = "Login";
this.bLogin.Click += new System.EventHandler(this.OnClickLogin);
//
// lPassword
//
this.lPassword.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.lPassword.Location = new System.Drawing.Point(30, 205);
this.lPassword.Name = "lPassword";
this.lPassword.Size = new System.Drawing.Size(80, 20);
this.lPassword.TabIndex = 11;
this.lPassword.Text = "Password";
this.lPassword.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// lUsername
//
this.lUsername.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.lUsername.Location = new System.Drawing.Point(30, 165);
this.lUsername.Name = "lUsername";
this.lUsername.Size = new System.Drawing.Size(80, 20);
this.lUsername.TabIndex = 10;
this.lUsername.Text = "Username";
this.lUsername.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// tbPassword
//
this.tbPassword.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.tbPassword.Location = new System.Drawing.Point(130, 205);
this.tbPassword.Name = "tbPassword";
this.tbPassword.Size = new System.Drawing.Size(270, 20);
this.tbPassword.TabIndex = 7;
this.tbPassword.Text = "";
//
// pHeader
//
this.pHeader.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
this.pHeader.Controls.AddRange(new System.Windows.Forms.Control[] {
this.lHeader,
this.lText,
this.pbImage});
this.pHeader.Dock = System.Windows.Forms.DockStyle.Top;
this.pHeader.Name = "pHeader";
this.pHeader.Size = new System.Drawing.Size(460, 60);
this.pHeader.TabIndex = 8;
//
// lHeader
//
this.lHeader.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.lHeader.Location = new System.Drawing.Point(10, 10);
this.lHeader.Name = "lHeader";
this.lHeader.Size = new System.Drawing.Size(360, 20);
this.lHeader.TabIndex = 3;
this.lHeader.Text = "Login";
this.lHeader.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// lText
//
this.lText.Location = new System.Drawing.Point(20, 30);
this.lText.Name = "lText";
this.lText.Size = new System.Drawing.Size(360, 20);
this.lText.TabIndex = 4;
this.lText.Text = "Please enter your Username and Password.";
this.lText.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// pbImage
//
this.pbImage.Image = ((System.Drawing.Bitmap)(resources.GetObject("pbImage.Image")));
this.pbImage.Location = new System.Drawing.Point(388, 5);
this.pbImage.Name = "pbImage";
this.pbImage.Size = new System.Drawing.Size(48, 48);
this.pbImage.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
this.pbImage.TabIndex = 5;
this.pbImage.TabStop = false;
//
// tbUsername
//
this.tbUsername.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.tbUsername.Location = new System.Drawing.Point(130, 165);
this.tbUsername.Name = "tbUsername";
this.tbUsername.Size = new System.Drawing.Size(270, 20);
this.tbUsername.TabIndex = 6;
this.tbUsername.Text = "";
//
// LoginControl
//
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.bLogin,
this.lPassword,
this.lUsername,
this.tbPassword,
this.pHeader,
this.tbUsername});
this.Name = "LoginControl";
this.Size = new System.Drawing.Size(460, 300);
this.Load += new System.EventHandler(this.OnLoad);
this.pHeader.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
static void Main()
{
}
///
/// OnLoad currently only defines the value tbPassword.PasswordChar.
///
private void OnLoad(object sender, System.EventArgs e)
{
tbPassword.PasswordChar = '\u25CF';
if (bCheck)
{
tmpU = theUsername;
tmpP = thePassword;
}
}
private void OnClickLogin(object sender, System.EventArgs e)
{
if (!bCheck)
{
if (!bHash)
{
theUsername = tbUsername.Text;
thePassword = tbPassword.Text;
if (Ready != null)
{
Ready(this, new System.EventArgs());
}
}
else
{
theUsername = HashString(tbUsername.Text);
thePassword = HashString(tbPassword.Text);
if (Ready != null)
{
Ready(this, new System.EventArgs());
}
}
}
else
{
bool b = CheckCredentials(tmpU, tmpP);
if (b)
{
if (Ready != null)
{
Successful(this, new System.EventArgs());
}
}
else
{
if (Ready != null)
{
Failed(this, new System.EventArgs());
}
}
}
}
///
/// Public property defining the headline text.
///
public string labelHeadline
{
get
{
return lHeader.Text;
}
set
{
lHeader.Text = value;
}
}
///
/// Public property defining the header text.
///
public string labelHeader
{
get
{
return lText.Text;
}
set
{
lText.Text = value;
}
}
///
/// Public property defining the label text before the Username textbox.
///
public string labelUsername
{
get
{
return lUsername.Text;
}
set
{
lUsername.Text = value;
}
}
///
/// Public property defining the label text before the Password textbox.
///
public string labelPassword
{
get
{
return lPassword.Text;
}
set
{
lPassword.Text = value;
}
}
///
/// Public property defining the text on the login button.
///
public string labelButton
{
get
{
return bLogin.Text;
}
set
{
bLogin.Text = value;
}
}
///
/// Public property to transfer the Username between the Host Application and LoginControl.
///
public string Username
{
get
{
return theUsername;
}
set
{
theUsername = value;
}
}
///
/// Public property to transfer the Password between the Host Application and LoginControl.
///
public string Password
{
get
{
return thePassword;
}
set
{
thePassword = value;
}
}
///
/// Property NoCheck. Defines if the validation of Username and Password is handled by the Host Application (True) or LoginControl (False).
///
public bool Check
{
get
{
return bCheck;
}
set
{
bCheck = value;
}
}
///
/// Property NoHash. Defines if the user data is hashed (False).
///
public bool Hash
{
get
{
return bHash;
}
set
{
bHash= value;
}
}
///
/// If NoCheck is set to false this method checks Username and Password.
///
private bool CheckCredentials(string usr, string pwd)
{
if (!bHash)
{
if (tbUsername.Text == usr)
{
if (tbPassword.Text == pwd)
{
return true;
}
else
{
errorProvider.SetError(bLogin, ErrMsg);
return false;
}
}
else
{
errorProvider.SetError(bLogin, ErrMsg);
return false;
}
}
else
{
if (HashString(tbUsername.Text) == HashString(usr))
{
if (HashString(tbPassword.Text) == HashString(pwd))
{
return true;
}
else
{
errorProvider.SetError(bLogin, ErrMsg);
return false;
}
}
else
{
errorProvider.SetError(bLogin, ErrMsg);
return false;
}
}
}
///
/// If NoHash is set to false HashPassword ... well ... hashes the password.
///
private string HashString(string s)
{
UTF8Encoding UTF8 = new UTF8Encoding();
byte[] data = UTF8.GetBytes(s);
MD5 md5 = new MD5CryptoServiceProvider();
byte[] result = md5.ComputeHash(data);
return System.Text.Encoding.UTF8.GetString(result);
}
///
/// Error message for the ErrorProvider.
///
public string ErrorMessage
{
get
{
return ErrMsg;
}
set
{
ErrMsg = value;
}
}
}
}