Advertisement
Guest User

Untitled

a guest
Oct 16th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.16 KB | None | 0 0
  1.     private void Checkpassword()
  2.     {
  3.         try
  4.         {
  5.  
  6.             using (SqlCommand sqlCommand = new SqlCommand("SELECT COUNT(*) from login where username like @username AND password like @password", myConnection))
  7.             {
  8.                 myConnection.Open();
  9.                 string userName = UsernameBox.Text;
  10.                 string passWord = Passwordbox.Text;
  11.                 sqlCommand.Parameters.AddWithValue("@username", userName);
  12.                 sqlCommand.Parameters.AddWithValue("@password", passWord);
  13.                 int userCount = (int)sqlCommand.ExecuteScalar();
  14.                 if(userCount > 0)
  15.                 {
  16.                     Session["username"] = userName;
  17.                     Session["password"] = passWord;
  18.                     myConnection.Close();
  19.                     Response.Redirect("AdminPage.aspx");
  20.  
  21.                 }
  22.                 else
  23.                 {
  24.                     StatusLabel.Text = "Incorrect username or password";
  25.                     myConnection.Close();
  26.                 }
  27.             }
  28.  
  29.         }
  30.         catch (Exception ex)
  31.         {
  32.             myConnection.Close();
  33.         }
  34.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement