Advertisement
Guest User

Untitled

a guest
Jun 4th, 2018
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.47 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Data.SqlClient;
  5. using System.Linq;
  6. using System.Web;
  7. using System.Web.UI;
  8. using System.Web.UI.WebControls;
  9.  
  10. namespace WebApplication1
  11. {
  12. public partial class LoginPage : System.Web.UI.Page
  13. {
  14. protected void Page_Load(object sender, EventArgs e)
  15. {
  16.  
  17. }
  18.  
  19. protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
  20. {
  21. String mycon = "Data Source=DESKTOP-LGI18UP;Initial Catalog=haritiShopping;Integrated Security = True";
  22. SqlConnection scon = new SqlConnection(mycon);
  23. String myquery = "select * from logindetails";
  24. SqlCommand cmd = new SqlCommand();
  25. cmd.CommandText = myquery;
  26. cmd.Connection = scon;
  27. SqlDataAdapter da = new SqlDataAdapter();
  28. da.SelectCommand = cmd;
  29. DataSet ds = new DataSet();
  30. da.Fill(ds);
  31. String uname;
  32. String pass;
  33. uname = ds.Tables[0].Rows[0]["username"].ToString();
  34. pass = ds.Tables[0].Rows[0]["password"].ToString();
  35. scon.Close();
  36. if (uname == TextBox1.Text && pass == TextBox2.Text)
  37. {
  38.  
  39. Response.Redirect("MainPage.aspx");
  40. }
  41.  
  42. else
  43. {
  44. Label1.Text = "Invalid Username or Password - Relogin with Correct Username Password";
  45. }
  46.  
  47. }
  48. protected void Button1_Click(object sender, EventArgs e)
  49. {
  50. String mycon = "Data Source=DESKTOP-LGI18UP;Initial Catalog=haritiShopping;Integrated Security = True";
  51. SqlConnection scon = new SqlConnection(mycon);
  52. SqlCommand cmd = new SqlCommand("select * from logindetails where UserName =@username and Password=@password", scon);
  53. cmd.Parameters.AddWithValue("@username", TextBox1.Text);
  54. cmd.Parameters.AddWithValue("@password", TextBox2.Text);
  55. SqlDataAdapter da = new SqlDataAdapter(cmd);
  56. DataTable dt = new DataTable();
  57. da.Fill(dt);
  58. if (dt.Rows.Count > 0)
  59.  
  60. {
  61.  
  62. Response.Redirect("MainPage.aspx");
  63.  
  64. }
  65.  
  66. else
  67.  
  68. {
  69.  
  70. Label1.Visible = true;
  71. Label1.Text = "Wrong password or nickname";
  72. }
  73. }
  74. /*protected void Button1_Click(object sender, EventArgs e)
  75. {
  76. String mycon = "Data Source=DESKTOP-LGI18UP;Initial Catalog=haritiShopping;Integrated Security = True";
  77. SqlConnection scon = new SqlConnection(mycon);
  78. String myquery = "select * from logindetails";
  79. SqlCommand cmd = new SqlCommand();
  80. cmd.CommandText = myquery;
  81. cmd.Connection = scon;
  82. SqlDataAdapter da = new SqlDataAdapter();
  83. da.SelectCommand = cmd;
  84. DataSet ds = new DataSet();
  85. da.Fill(ds);
  86. String uname;
  87. String pass;
  88. uname = ds.Tables[0].Rows[0]["username"].ToString();
  89. pass = ds.Tables[0].Rows[0]["password"].ToString();
  90. scon.Close();
  91. if (uname == TextBox1.Text && pass == TextBox2.Text)
  92. {
  93.  
  94. Response.Redirect("MainPage.aspx");
  95. }
  96.  
  97. else
  98. {
  99. Response.Redirect("MainPage.aspx");
  100. }
  101. }
  102. */}
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement