Advertisement
Guest User

Untitled

a guest
Mar 3rd, 2019
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.57 KB | None | 0 0
  1.  protected void Page_Load(object sender, EventArgs e)
  2.         {
  3.             this.cmd = Convert.ToInt16(Request["cmd"]);
  4.             this.username = Request["username"].ToString();
  5.             this.password = Request["password"].ToString();
  6.  
  7.             switch (cmd)
  8.             {
  9.                 case 1:
  10.                     string res = IsUser();
  11.                     Response.Redirect(res);
  12.                     break;
  13.             }
  14.  
  15.         }
  16.  
  17.        
  18.         public string IsUser()
  19.         {
  20.             string resultat="";
  21.             SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=D:\Gabriel\Documents\Teccart\session_4\ASP\dating\dating\App_Data\datingBd.mdf;Integrated Security=True");
  22.             con.Open();
  23.             SqlCommand isuser = new SqlCommand("select * from users where username = @u and password = @p;",con);
  24.             //SqlCommand isuser = new SqlCommand("select * from users where username=@u;",con);
  25.             isuser.Parameters.AddWithValue("@u", username);
  26.             isuser.Parameters.AddWithValue("@p", password);
  27.  
  28.             SqlDataReader reader = isuser.ExecuteReader();
  29.                 while (reader.Read())
  30.                 {
  31.                     if (reader.HasRows)
  32.                     {
  33.                         resultat = "1";
  34.                     }
  35.                     else
  36.                     {
  37.                         resultat = "0";
  38.                     }
  39.                 }
  40.  
  41.                 return resultat;
  42.            
  43.  
  44.            
  45.  
  46.             con.Close();
  47.         }
  48.  
  49.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement