Guest User

Untitled

a guest
Dec 15th, 2016
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.47 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. // "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. Console.ForegroundColor = ConsoleColor.White;
  22. Console.WriteLine("Connecting...");
  23. string mysqlogin = "server=localhost;user=root;database=firstapp;port=3306;password=";
  24. try
  25. {
  26. getdb = new MySqlConnection(mysqlogin);
  27. getdb.Open();
  28. Console.ForegroundColor = ConsoleColor.Green;
  29. Console.WriteLine("Connected!");
  30. Console.ForegroundColor = ConsoleColor.White;
  31. username();
  32. }
  33. catch (MySqlException)
  34. {
  35. MessageBox.Show("Unable to Connect! retrying...","Error!");
  36. retdb();
  37. }
  38. }
  39. private static void username()
  40. {
  41. Console.WriteLine("Username: ");
  42. MySqlConnection getdb;
  43. string mysqlogin = "server=localhost;user=root;database=firstapp;port=3306;password=";
  44. string usernamefield = Console.ReadLine();
  45. try
  46. {
  47. getdb = new MySqlConnection(mysqlogin);
  48. getdb.Open();
  49. MySqlCommand querydata = new MySqlCommand("SELECT * FROM userdata WHERE username ='" + usernamefield + "'", getdb);
  50. MySqlDataReader retuser;
  51. int count = 0;
  52. retuser = querydata.ExecuteReader();
  53. while (retuser.Read())
  54. {
  55. count = count + 1;
  56. }
  57. if (count == 1)
  58. {
  59. password();
  60. }
  61. else if (count == 0)
  62. {
  63. Console.ForegroundColor = ConsoleColor.Red;
  64. Console.WriteLine("Invalid Username!");
  65. Console.ForegroundColor = ConsoleColor.White;
  66. username();
  67. }
  68. }
  69. catch (MySqlException)
  70. {
  71. MessageBox.Show("Unable to Connect! retrying...", "Error!");
  72. retdb();
  73. }
  74. }
  75. private static void password()
  76. {
  77. Console.WriteLine("Password: ");
  78. MySqlConnection getdb;
  79. string mysqlogin = "server=localhost;user=root;database=firstapp;port=3306;password=";
  80. string passfield = Console.ReadLine();
  81. try
  82. {
  83. getdb = new MySqlConnection(mysqlogin);
  84. getdb.Open();
  85. MySqlCommand querydata1 = new MySqlCommand("SELECT * FROM userdata WHERE password ='" + passfield + "'", getdb);
  86. MySqlDataReader retpw;
  87. int count = 0;
  88. retpw = querydata1.ExecuteReader();
  89. while (retpw.Read())
  90. {
  91. count = count + 1;
  92. }
  93. if (count == 1)
  94. {
  95. logged();
  96. }
  97. else if (count == 0)
  98. {
  99. Console.ForegroundColor = ConsoleColor.Red;
  100. Console.WriteLine("Invalid Password!");
  101. Console.ForegroundColor = ConsoleColor.White;
  102. username();
  103. }
  104. }
  105. catch (MySqlException)
  106. {
  107. MessageBox.Show("Unable to Connect! retrying...", "Error!");
  108. retdb();
  109. }
  110. }
  111. static void logged()
  112. {
  113. bool logged = true;
  114. Console.ForegroundColor = ConsoleColor.White;
  115. Console.WriteLine("Welcome to xrx Interface!");
  116. Console.WriteLine("How i can help you today?");
  117. Console.WriteLine("Type ''help'' to see whats available");
  118. while (logged)
  119. {
  120. string[] cmds = new string[3] { "help", "logoff", "about" };
  121. string[] cmdresponse = new string[2] { "y", "n" };
  122. string cmdline = Console.ReadLine();
  123. if (cmdline == cmds[0])
  124. {
  125. Console.WriteLine("Available Commands: {0} {1} {2}", cmds);
  126. }
  127. else if (cmdline == cmds[1])
  128. {
  129. Console.WriteLine("Are you sure? (y or n)");
  130. cmdline = Console.ReadLine();
  131. if (cmdline == cmdresponse[0])
  132. {
  133. username();
  134. }
  135. }
  136. else if (cmdline == cmds[2])
  137. {
  138. Console.WriteLine("Created by xrx on 12/12/2016");
  139. }
  140. else
  141. {
  142. Console.ForegroundColor = ConsoleColor.Red;
  143. Console.WriteLine("Command Not Found!");
  144. Console.ForegroundColor = ConsoleColor.White;
  145. }
  146. }
  147. }
  148. static void Main(string[] args)
  149. {
  150. retdb();
  151. username();
  152. }
  153. }
  154. }
Add Comment
Please, Sign In to add comment