Advertisement
Guest User

Untitled

a guest
Dec 21st, 2016
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.05 KB | None | 0 0
  1. using 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. namespace ConsoleApplication2
  13. {
  14. class Program
  15. {
  16. static int retries = 1;
  17. static int maxretries = 7;
  18. private static void retrieveconnection()
  19. {
  20. if (retries == maxretries)
  21. {
  22. MessageBox.Show("Connection failed after 5 retries! exiting...", "Error", MessageBoxButtons.OK ,MessageBoxIcon.Error);
  23. Environment.Exit(0);
  24. }
  25. MySqlConnection getdb;
  26. string mysqlogin = "server=localhost;user=root;database=firstapp;port=3306;password=";
  27. try
  28. {
  29. getdb = new MySqlConnection(mysqlogin);
  30. getdb.Open();
  31. login();
  32. }
  33. catch (MySqlException)
  34. {
  35. MessageBox.Show("Unable to Connect! retrying..", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
  36. retries++;
  37. retrieveconnection();
  38. }
  39. }
  40. private static void login()
  41. {
  42. retries = 1;
  43. Console.WriteLine("Username: ");
  44. string username = Console.ReadLine();
  45. Console.WriteLine("Password: ");
  46. string password = Console.ReadLine();
  47. MySqlConnection getdb;
  48. string mysqlogin = "server=localhost;user=root;database=firstapp;port=3306;password=";
  49. try
  50. {
  51. getdb = new MySqlConnection(mysqlogin);
  52. getdb.Open();
  53. MySqlCommand querydata = new MySqlCommand("SELECT * FROM userdata WHERE username='" + username + "' AND password='" + password + "'" ,getdb);
  54. MySqlDataReader retdata;
  55. int count = 0;
  56. retdata = querydata.ExecuteReader();
  57. while (retdata.Read())
  58. {
  59. count = count + 1;
  60. }
  61. if (count == 1)
  62. {
  63. logged();
  64. }
  65. else if (count == 0)
  66. {
  67. MessageBox.Show("Invalid Login Details!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
  68. login();
  69. }
  70. }
  71. catch (MySqlException)
  72. {
  73. retrieveconnection();
  74. login();
  75. }
  76. }
  77. static void logged()
  78. {
  79. bool logged = true;
  80. Console.WriteLine("Welcome to xrx Interface!");
  81. Console.WriteLine("How i can help you today?");
  82. Console.WriteLine("Type ''help'' to see whats available");
  83. while (logged)
  84. {
  85. string[] cmds = new string[3] { "help", "logoff", "about" };
  86. string[] cmdresponse = new string[2] { "y", "n" };
  87. string cmdline = Console.ReadLine();
  88. if (cmdline == cmds[0])
  89. {
  90. Console.WriteLine("Available Commands: {0} {1} {2}", cmds);
  91. }
  92. else if (cmdline == cmds[1])
  93. {
  94. Console.WriteLine("Are you sure? (y or n)");
  95. cmdline = Console.ReadLine();
  96. if (cmdline == cmdresponse[0])
  97. {
  98. login();
  99. }
  100. }
  101. else if (cmdline == cmds[2])
  102. {
  103. Console.WriteLine("Created by xrx on 21/12/2016");
  104. }
  105. else
  106. {
  107. Console.WriteLine("Command Not Found!");
  108. }
  109. }
  110. }
  111. static void Main(string[] args)
  112. {
  113. Console.Title = "xrx interface v3.0";
  114. retrieveconnection();
  115. login();
  116. }
  117. }
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement