Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using MySql.Data.MySqlClient;
- using MySql.Data;
- using System.Windows.Forms;
- using System.Data;
- using System.Data.SqlClient;
- namespace ConsoleApplication2
- {
- class Program
- {
- static int retries = 1;
- static int maxretries = 7;
- private static void retrieveconnection()
- {
- if (retries == maxretries)
- {
- MessageBox.Show("Connection failed after 5 retries! exiting...", "Error", MessageBoxButtons.OK ,MessageBoxIcon.Error);
- Environment.Exit(0);
- }
- MySqlConnection getdb;
- string mysqlogin = "server=localhost;user=root;database=firstapp;port=3306;password=";
- try
- {
- getdb = new MySqlConnection(mysqlogin);
- getdb.Open();
- login();
- }
- catch (MySqlException)
- {
- MessageBox.Show("Unable to Connect! retrying..", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
- retries++;
- retrieveconnection();
- }
- }
- private static void login()
- {
- retries = 1;
- Console.WriteLine("Username: ");
- string username = Console.ReadLine();
- Console.WriteLine("Password: ");
- string password = Console.ReadLine();
- MySqlConnection getdb;
- string mysqlogin = "server=localhost;user=root;database=firstapp;port=3306;password=";
- try
- {
- getdb = new MySqlConnection(mysqlogin);
- getdb.Open();
- MySqlCommand querydata = new MySqlCommand("SELECT * FROM userdata WHERE username='" + username + "' AND password='" + password + "'" ,getdb);
- MySqlDataReader retdata;
- int count = 0;
- retdata = querydata.ExecuteReader();
- while (retdata.Read())
- {
- count = count + 1;
- }
- if (count == 1)
- {
- logged();
- }
- else if (count == 0)
- {
- MessageBox.Show("Invalid Login Details!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
- login();
- }
- }
- catch (MySqlException)
- {
- retrieveconnection();
- login();
- }
- }
- static void logged()
- {
- bool logged = true;
- Console.WriteLine("Welcome to xrx Interface!");
- Console.WriteLine("How i can help you today?");
- Console.WriteLine("Type ''help'' to see whats available");
- while (logged)
- {
- string[] cmds = new string[3] { "help", "logoff", "about" };
- string[] cmdresponse = new string[2] { "y", "n" };
- string cmdline = Console.ReadLine();
- if (cmdline == cmds[0])
- {
- Console.WriteLine("Available Commands: {0} {1} {2}", cmds);
- }
- else if (cmdline == cmds[1])
- {
- Console.WriteLine("Are you sure? (y or n)");
- cmdline = Console.ReadLine();
- if (cmdline == cmdresponse[0])
- {
- login();
- }
- }
- else if (cmdline == cmds[2])
- {
- Console.WriteLine("Created by xrx on 21/12/2016");
- }
- else
- {
- Console.WriteLine("Command Not Found!");
- }
- }
- }
- static void Main(string[] args)
- {
- Console.Title = "xrx interface v3.0";
- retrieveconnection();
- login();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement