Advertisement
Guest User

Untitled

a guest
Dec 11th, 2016
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using MySql.Data.MySqlClient;
  7. using MySql.Data;
  8. using System.Windows.Forms;
  9. using System.Data;
  10. using System.Data.SqlClient;
  11.  
  12. // "SELECT * FROM userdata WHERE username=" + username + "password = " + password"
  13.  
  14. namespace ConsoleApplication4
  15. {
  16. class Program
  17. {
  18. private static void retdb()
  19. {
  20. MySqlConnection getdb;
  21. string mysqlogin = "server=localhost;user=root;database=firstapp;port=3306;password=";
  22. try
  23. {
  24. getdb = new MySqlConnection(mysqlogin);
  25. getdb.Open();
  26. }
  27. catch (MySqlException)
  28. {
  29. MessageBox.Show("Unable to Connect! retrying...","Error!");
  30. retdb();
  31. }
  32. }
  33. private static void login()
  34. {
  35. Console.WriteLine("Username: ");
  36. MySqlConnection getdb;
  37. string mysqlogin = "server=localhost;user=root;database=firstapp;port=3306;password=";
  38. string usernamefield = Console.ReadLine();
  39. try
  40. {
  41. getdb = new MySqlConnection(mysqlogin);
  42. getdb.Open();
  43. MySqlCommand querydata = new MySqlCommand("SELECT * FROM userdata WHERE username =" +usernamefield , getdb);
  44. MySqlDataReader retuser;
  45. int count = 0;
  46. retuser = querydata.ExecuteReader();
  47. while (retuser.Read())
  48. {
  49. count = count + 1;
  50. }
  51. if (count == 1)
  52. {
  53. Console.WriteLine("correct");
  54. }
  55. else if (count == 0)
  56. {
  57. Console.WriteLine("wrong");
  58. login();
  59. }
  60. }
  61. catch (MySqlException ex)
  62. {
  63. Console.WriteLine(ex.ToString(), "Error!");
  64. login();
  65. }
  66. }
  67. static void Main(string[] args)
  68. {
  69. retdb();
  70. login();
  71. }
  72. }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement