Friday, April 18, 2008

Simple Code for login

protected void btnsubmit_Click(object sender, EventArgs e)
{
scn.Open();
SqlCommand cmd = new SqlCommand("select pwd from Registration where userid='" + txtname.Text + "'", scn);
string str = Convert.ToString(cmd.ExecuteScalar());
if (str == "")
{
Label1.Visible = true;
Label1.Text = "Login failed";
txtname.Text = "";
txtpassword.Text = "";
}

else
{
if (txtpassword.Text == str)
{
Session["userid"] = txtname.Text;
Session["password"] = txtpassword.Text;
Response.Redirect("mailrouting.aspx");
Label1.Visible = false;
txtname.Text = "";
txtpassword.Text = "";

Response.Redirect("mailrouting.aspx");


}
else
{
Label1.Visible = true;
Label1.Text = "Incorrect Password";
txtname.Text = "";
txtpassword.Text = "";

}
}

scn.Close();
}

No comments:

Using Authorization with Swagger in ASP.NET Core

 Create Solution like below LoginModel.cs using System.ComponentModel.DataAnnotations; namespace UsingAuthorizationWithSwagger.Models {     ...