Advertisement
Guest User

Untitled

a guest
Dec 3rd, 2016
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.51 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.  
  10. namespace ConsoleApplication1
  11. {
  12. class Program
  13. {
  14. private static void dbconn()
  15. {
  16. string getusername = "SELECT username FROM userdata";
  17. string getpw = "SELECT password FROM userdata";
  18. Console.ForegroundColor = ConsoleColor.White;
  19. Console.WriteLine("Connecting...");
  20. MySql.Data.MySqlClient.MySqlConnection conn;
  21. string myConnectionString;
  22.  
  23. myConnectionString = "server=127.0.0.1;uid=root;" +
  24. "pwd=;database=firstapp;";
  25.  
  26. try
  27. {
  28. conn = new MySql.Data.MySqlClient.MySqlConnection(myConnectionString);
  29. conn.Open();
  30. Console.ForegroundColor = ConsoleColor.Green;
  31. Console.WriteLine("Connected!");
  32. Console.ForegroundColor = ConsoleColor.White;
  33. MySqlCommand cmd = new MySqlCommand(getusername, conn);
  34. MySqlCommand cmd1 = new MySqlCommand(getpw, conn);
  35. }
  36. catch (MySql.Data.MySqlClient.MySqlException)
  37. {
  38. MessageBox.Show("Unable to Connect! closing...");
  39. Environment.Exit(0);
  40. }
  41. }
  42. static void login()
  43. {
  44. string username = "xrx"; //username
  45. Console.ForegroundColor = ConsoleColor.Yellow;
  46. Console.WriteLine("Username: ");
  47. Console.ForegroundColor = ConsoleColor.White;
  48. string userfield = Console.ReadLine();
  49. if (userfield == username)
  50. {
  51. password();
  52. }
  53. else
  54. {
  55. Console.ForegroundColor = ConsoleColor.Red;
  56. Console.WriteLine("Invalid Username!");
  57. Console.ForegroundColor = ConsoleColor.White;
  58. login();
  59. }
  60. }
  61. static void logged()
  62. {
  63. bool logged = true;
  64. Console.WriteLine("Welcome to xrx Interface!");
  65. Console.WriteLine("How i can help you today?");
  66. Console.WriteLine("Type ''help'' to see whats available");
  67. while (logged)
  68. {
  69. string[] cmds = new string[3] { "help", "logoff", "about" };
  70. string[] cmdresponse = new string[2] { "y", "n" };
  71. string cmdline = Console.ReadLine();
  72. if (cmdline == cmds[0])
  73. {
  74. Console.WriteLine("Available Commands: {0} {1} {2}", cmds);
  75. }
  76. else if (cmdline == cmds[1])
  77. {
  78. Console.WriteLine("Are you sure? (y or n)");
  79. cmdline = Console.ReadLine();
  80. if (cmdline == cmdresponse[0])
  81. {
  82. login();
  83. }
  84. }
  85. else if (cmdline == cmds[2])
  86. {
  87. Console.WriteLine("Created by xrx on 21/11/2016");
  88. }
  89. else
  90. {
  91. Console.ForegroundColor = ConsoleColor.Red;
  92. Console.WriteLine("Command Not Found!");
  93. Console.ForegroundColor = ConsoleColor.White;
  94. }
  95. }
  96. }
  97. static void password()
  98. {
  99. string password = "xrx1";
  100. Console.ForegroundColor = ConsoleColor.Yellow;
  101. Console.WriteLine("Password: ");
  102. Console.ForegroundColor = ConsoleColor.Black;
  103. string pwfield = Console.ReadLine();
  104. Console.ForegroundColor = ConsoleColor.White;
  105. if (pwfield == password)
  106. {
  107. Console.ForegroundColor = ConsoleColor.Green;
  108. Console.WriteLine("Access Granted!");
  109. Console.ForegroundColor = ConsoleColor.White;
  110. logged();
  111. }
  112. else
  113. {
  114. Console.ForegroundColor = ConsoleColor.Red;
  115. Console.WriteLine("Invalid Password!");
  116. Console.ForegroundColor = ConsoleColor.White;
  117. login();
  118. }
  119. }
  120. static void Main(string[] args)
  121. {
  122. Console.Title = "xrx interface v1.1";
  123. dbconn();
  124. login();
  125. }
  126. }
  127. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement