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;
- // "SELECT * FROM userdata WHERE username=" + username + "password = " + password"
- namespace ConsoleApplication4
- {
- class Program
- {
- private static void retdb()
- {
- MySqlConnection getdb;
- Console.ForegroundColor = ConsoleColor.White;
- Console.WriteLine("Connecting...");
- string mysqlogin = "server=localhost;user=root;database=firstapp;port=3306;password=";
- try
- {
- getdb = new MySqlConnection(mysqlogin);
- getdb.Open();
- Console.ForegroundColor = ConsoleColor.Green;
- Console.WriteLine("Connected!");
- Console.ForegroundColor = ConsoleColor.White;
- username();
- }
- catch (MySqlException)
- {
- MessageBox.Show("Unable to Connect! retrying...","Error!");
- retdb();
- }
- }
- private static void username()
- {
- Console.WriteLine("Username: ");
- MySqlConnection getdb;
- string mysqlogin = "server=localhost;user=root;database=firstapp;port=3306;password=";
- string usernamefield = Console.ReadLine();
- try
- {
- getdb = new MySqlConnection(mysqlogin);
- getdb.Open();
- MySqlCommand querydata = new MySqlCommand("SELECT * FROM userdata WHERE username ='" + usernamefield + "'", getdb);
- MySqlDataReader retuser;
- int count = 0;
- retuser = querydata.ExecuteReader();
- while (retuser.Read())
- {
- count = count + 1;
- }
- if (count == 1)
- {
- password();
- }
- else if (count == 0)
- {
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine("Invalid Username!");
- Console.ForegroundColor = ConsoleColor.White;
- username();
- }
- }
- catch (MySqlException)
- {
- MessageBox.Show("Unable to Connect! retrying...", "Error!");
- retdb();
- }
- }
- private static void password()
- {
- Console.WriteLine("Password: ");
- MySqlConnection getdb;
- string mysqlogin = "server=localhost;user=root;database=firstapp;port=3306;password=";
- string passfield = Console.ReadLine();
- try
- {
- getdb = new MySqlConnection(mysqlogin);
- getdb.Open();
- MySqlCommand querydata1 = new MySqlCommand("SELECT * FROM userdata WHERE password ='" + passfield + "'", getdb);
- MySqlDataReader retpw;
- int count = 0;
- retpw = querydata1.ExecuteReader();
- while (retpw.Read())
- {
- count = count + 1;
- }
- if (count == 1)
- {
- logged();
- }
- else if (count == 0)
- {
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine("Invalid Password!");
- Console.ForegroundColor = ConsoleColor.White;
- username();
- }
- }
- catch (MySqlException)
- {
- MessageBox.Show("Unable to Connect! retrying...", "Error!");
- retdb();
- }
- }
- static void logged()
- {
- bool logged = true;
- Console.ForegroundColor = ConsoleColor.White;
- 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])
- {
- username();
- }
- }
- else if (cmdline == cmds[2])
- {
- Console.WriteLine("Created by xrx on 12/12/2016");
- }
- else
- {
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine("Command Not Found!");
- Console.ForegroundColor = ConsoleColor.White;
- }
- }
- }
- static void Main(string[] args)
- {
- Console.Title = "xrx interface 2.0";
- retdb();
- username();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement