It's a basic thing. You have design form then why not code it ?
Every control has events. if you design the forms means you know the logic behind it.
just go ahead. here are some steps that will help you.
1. Validate empty Username and password textbox.
2. Make SQL connection and Fetch password with the help of username
3. if no record fetch alert user "Userid not exist"
4. if record exist check against entered password, if mismatched, alert user "Wrong password"
Here is example,Login with example C#.net[^]
Every control has events. if you design the forms means you know the logic behind it.
just go ahead. here are some steps that will help you.
1. Validate empty Username and password textbox.
2. Make SQL connection and Fetch password with the help of username
3. if no record fetch alert user "Userid not exist"
4. if record exist check against entered password, if mismatched, alert user "Wrong password"
Here is example,Login with example C#.net[^]
using System;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Security.Cryptography;
using System.Text;
using System.Windows.Forms;
namespace daniweb
{
public partial class frmLogin : Form
{
public frmLogin()
{
InitializeComponent();
}
#if (DEBUG) //Only compile this method for local debugging.
/// <summary>
/// Decrypt a string
/// </summary>
/// <param name="Value"></param>
/// <returns></returns>
private static string Decrypt(string Value)
{
SymmetricAlgorithm mCSP;
ICryptoTransform ct = null;
MemoryStream ms = null;
CryptoStream cs = null;
byte[] byt;
byte[] _result;
mCSP = new RijndaelManaged();
try
{
mCSP.Key = _key;
mCSP.IV = _initVector;
ct = mCSP.CreateDecryptor(mCSP.Key, mCSP.IV);
byt = Convert.FromBase64String(Value);
ms = new MemoryStream();
cs = new CryptoStream(ms, ct, CryptoStreamMode.Write);
cs.Write(byt, 0, byt.Length);
cs.FlushFinalBlock();
cs.Close();
_result = ms.ToArray();
}
catch
{
_result = null;
}
finally
{
if (ct != null)
ct.Dispose();
if (ms != null)
ms.Dispose();
if (cs != null)
cs.Dispose();
}
/// <summary>
/// Obviously the .Focus() code doesn't apply to ASP.NET
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonLogin_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBoxUsername.Text))
{
//Focus box before showing a message
textBoxUsername.Focus();
MessageBox.Show("Enter your username", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
//Focus again afterwards, sometimes people double click message boxes and select another control accidentally
textBoxUsername.Focus();
return;
}
else if (string.IsNullOrEmpty(textBoxPassword.Text))
{
textBoxPassword.Focus();
MessageBox.Show("Enter your password", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
textBoxPassword.Focus();
return;
}
//OK they enter a user and pass, lets see if they can authenticate
using (DataTable dt = LookupUser(textBoxUsername.Text))
{
if (dt.Rows.Count == 0)
{
textBoxUsername.Focus();
MessageBox.Show("Invalid username.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
textBoxUsername.Focus();
return;
}
else
{
//Always compare the resulting crypto string or hash value, never the decrypted value
//By doing that you never make a call to Decrypt() and the application is harder to
//reverse engineer. I included the Decrypt() method here for informational purposes
//only. I do not recommend shipping an assembly with Decrypt() methods.
string dbPassword = Convert.ToString(dt.Rows[0]["Password"]);
string appPassword = Encrypt(textBoxPassword.Text); //we store the password as encrypted in the DB
if (string.Compare(dbPassword, appPassword) == 0)
{
//Logged in
}
else
{
//You may want to use the same error message so they can't tell which field they got wrong
textBoxPassword.Focus();
MessageBox.Show("Invalid Password", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
textBoxPassword.Focus();
return;
}
}
}
}
}
}
EmoticonEmoticon