Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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;
- string mysqlogin = "server=localhost;user=root;database=firstapp;port=3306;password=";
- try
- {
- getdb = new MySqlConnection(mysqlogin);
- getdb.Open();
- }
- catch (MySqlException)
- {
- MessageBox.Show("Unable to Connect! retrying...","Error!");
- retdb();
- }
- }
- private static void login()
- {
- 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)
- {
- Console.WriteLine("correct");
- }
- else if (count == 0)
- {
- Console.WriteLine("wrong");
- login();
- }
- }
- catch (MySqlException ex)
- {
- Console.WriteLine(ex.ToString(), "Error!");
- login();
- }
- }
- static void Main(string[] args)
- {
- retdb();
- login();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement