Authneticating a User using SQL Database.

Chvrsri
Posted by Chvrsri under C# category on | Points: 40 | Views : 2228
Hi this is for starters !!! This code explains how to authenticate a user by using his UserName and Password !!!

This is the Code sample ::


private void Page_Load(object sender, System.EventArgs e)
{

SqlConnection con;
int abc= 0;
con = new SqlConnection("server=user-182;user id=sa;password=007;database=srikanthch");
con.Open();
SqlCommand cmd;
SqlDataReader rdr;
cmd = new SqlCommand("select name,id from Srikanth",con);
rdr=cmd.ExecuteReader();
while (rdr.Read())
{
if (rdr["name"].ToString() == textBox1.Text && rdr["id"].ToString() == textBox2.Text)
{
Response.write("valid");
abc = 1;
}
}
if (abc == 0)
{
Response.write("invalid");

}

}


Cheers !!!

Comments or Responses

Login to post response