Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.21 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.Data.SqlClient;
  11.  
  12.  
  13. namespace WindowsFormsApplication1
  14. {
  15. public partial class LOGIN : Form
  16. {
  17. public LOGIN()
  18. {
  19. InitializeComponent();
  20. }
  21.  
  22. private void button2_Click(object sender, EventArgs e)
  23. {
  24. this.Close();
  25. }
  26.  
  27. private void button1_Click(object sender, EventArgs e)
  28. {
  29.  
  30. SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)v11.0;AttachDbFilename=C:UserskenluiDocumentsLoginDate.mdf;Integrated Security=True;Connect Timeout=30;");
  31. SqlDataAdapter sda = new SqlDataAdapter("Select Count(*) from Login where Username ='" + textBox1.Text + "' and Password = '" + textBox2.Text + "'", con);
  32. DataTable dt = new DataTable();
  33. sda.Fill(dt);
  34. if (dt.Rows[0][0].ToString() == "1")
  35. {
  36. this.Hide();
  37. main ss = new main();
  38. ss.Show();
  39.  
  40.  
  41. }
  42. else
  43. {
  44. MessageBox.Show("Please Check Username and Password");
  45. }
  46. }
  47. }
  48. }
  49.  
  50. private void button1_Click(object sender, EventArgs e)
  51. {
  52. using (SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)v11.0;AttachDbFilename=C:UserskenluiDocumentsLoginDate.mdf;Integrated Security=True;Connect Timeout=30;"))
  53. using (SqlDataAdapter sda = new SqlDataAdapter("Select Count(*) from Login where Username = @userName and Password = @password", con))
  54. using (DataTable dt = new DataTable())
  55. {
  56. sda.SelectCommand.Parameters.Add(new SqlParameter("@userName", SqlDbType.VarChar) { Value = textBox1.Text });
  57. // this should be a hash of the password, not the plain text value
  58. sda.SelectCommand.Parameters.Add(new SqlParameter("@password", SqlDbType.VarChar) { Value = textBox2.Text });
  59.  
  60. sda.Fill(dt);
  61. if (dt.Rows[0][0].ToString() == "1")
  62. {
  63. this.Hide();
  64. main ss = new main();
  65. ss.Show();
  66. }
  67. else
  68. {
  69. MessageBox.Show("Please Check Username and Password");
  70. }
  71. }
  72. }
  73.  
  74. private void button1_Click(object sender, EventArgs e)
  75. {
  76. using (SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)v11.0;AttachDbFilename=C:UserskenluiDocumentsLoginDate.mdf;Integrated Security=True;Connect Timeout=30;"))
  77. using (SqlCommand sda = new SqlCommand("Select 1 from Login where Username = @userName and Password = @password", con))
  78. {
  79. sda.Parameters.Add(new SqlParameter("@userName", SqlDbType.VarChar) { Value = textBox1.Text });
  80. // this should be a hash of the password, not the plain text value
  81. sda.Parameters.Add(new SqlParameter("@password", SqlDbType.VarChar) { Value = textBox2.Text });
  82. var result = sda.ExecuteScalar();
  83.  
  84. if (result != null && 1 == (int)result)
  85. {
  86. this.Hide();
  87. main ss = new main();
  88. ss.Show();
  89. }
  90. else
  91. {
  92. MessageBox.Show("Please Check Username and Password");
  93. }
  94. }
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement