Advertisement
Guest User

Untitled

a guest
Aug 21st, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.41 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.Windows.Forms;
  9. using MySql.Data.MySqlClient;
  10.  
  11. namespace ECBSRecruitmentAgencySoftware
  12. {
  13. public partial class LogIn : Form
  14. {
  15. public LogIn()
  16. {
  17. InitializeComponent();
  18. }
  19.  
  20. public bool tryLogin(string username, string password)
  21. {
  22. MySqlConnection con = new MySqlConnection("host=think-tek.net;user=ctutorial;password=chang3d;database=ctutorial_logintest;");
  23. MySqlCommand cmd = new MySqlCommand("Select * FROM login WHERE user_name = `" + username + "` AND user_pass = `" + password + "`;");
  24. cmd.Connection = con;
  25. con.Open();
  26. MySqlDataReader reader = cmd.ExecuteReader();
  27. if (reader.Read() != false)
  28. {
  29. if (reader.IsDBNull(0) == true)
  30. {
  31. cmd.Connection.Close();
  32. reader.Dispose();
  33. cmd.Dispose();
  34. return false;
  35. }
  36. else
  37. {
  38. cmd.Connection.Close();
  39. reader.Dispose();
  40. cmd.Dispose();
  41. return true;
  42. }
  43. }
  44. else
  45. {
  46. return false;
  47. }
  48. }
  49. private void button1_Click(object sender, EventArgs e)
  50. {
  51.  
  52. if (tryLogin(textBox1.Text, textBox2.Text) == true)
  53. {
  54. MainScreen F2 = new MainScreen();
  55. F2.Show();
  56. this.Hide();
  57. }
  58.  
  59. else MessageBox.Show("Wrong details!");
  60.  
  61. }
  62.  
  63.  
  64.  
  65.  
  66. }
  67. }
  68.  
  69. string mySqlConn = "server=localhost;user=username;database=databasename;port=3306;password=password;";
  70.  
  71. public bool tryLogin(string username, string password)
  72. {
  73. MySqlConnection con = new MySqlConnection("SERVER=localhost;" +
  74. "DATABASE=mydatabase;" +
  75. "UID=testuser;" +
  76. "PASSWORD=testpassword;");
  77. MySqlCommand cmd = new MySqlCommand("Select * FROM login WHERE user_name = `" + username + "` AND user_pass = `" + password + "`;");
  78. cmd.Connection = con;
  79. con.Open();
  80. MySqlDataReader reader = cmd.ExecuteReader();
  81. if (reader.Read() != false)
  82. {
  83. if (reader.IsDBNull(0) == true)
  84. {
  85. cmd.Connection.Close();
  86. reader.Dispose();
  87. cmd.Dispose();
  88. return false;
  89. }
  90. else
  91. {
  92. cmd.Connection.Close();
  93. reader.Dispose();
  94. cmd.Dispose();
  95. return true;
  96. }
  97. }
  98. else
  99. {
  100. return false;
  101. }
  102. }
  103.  
  104. string connection = "server=localhost;database=student_record_database;user=root;password=;";
  105. MySqlConnection con = new MySqlConnection(connection);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement