Guest User

Guest User

  • Tech Writer
  • 271
  • 36k

Check username and password is incorrect in asp.net

Jul 30 2020 1:19 AM
when user login if username is incorrect then it will show error if password is incorrect its shows error...in my code its is username or password is incorrect then it will show error.. i want for both condition.this all done by Entity Framework
 
protected void Button1_Click(object sender, EventArgs e)
{
string UserName = TxtUserName.Text;
WallpaperEntities4 db = new WallpaperEntities4();
string ID = Request.QueryString["Id"];
string query = (from c in db.Users
where c.UserName == TxtUserName.Text && c.Password == TxtPassword.Text
select c.UserName).FirstOrDefault();
if (query != null)
{
Session["UserName"] = UserName;
Response.Redirect("/Walpaper.aspx?username="+UserName);
}
else
LblMesge.Text = "Invalid User or password";
}
 

Answers (6)