Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.76 KB | None | 0 0
  1. using System;
  2. using System.Data;
  3. using System.Windows.Forms;
  4. using MySql.Data.MySqlClient;
  5.  
  6. namespace MySql_Login_Form
  7. {
  8.     public partial class Form1 : Form
  9.     {
  10.         public Form1()
  11.         {
  12.             InitializeComponent();
  13.         }
  14.  
  15.         MySqlConnection connection = new MySqlConnection("Server=sql7.freesqldatabase.com;Port=3306;Database=sql7111967;User Id=sql7111967;Password=P3gsMx3fZT;");
  16.         MySqlDataAdapter adapter;
  17.         DataTable table = new DataTable();
  18.        
  19.  
  20.         private void loginBtn_Click(object sender, EventArgs e)
  21.         {
  22.             try
  23.             {
  24.                 adapter = new MySqlDataAdapter("SELECT username, password FROM users WHERE username = '" + usernameTxt.Text + "' AND password = '" + passwordTxt.Text + "'", connection);
  25.                 adapter.Fill(table);
  26.                 if (table.Rows.Count >= 1)
  27.                 {
  28.                     MessageBox.Show("Login");
  29.                 }
  30.                 else
  31.                 {
  32.                     MessageBox.Show("False password or username");
  33.                 }
  34.             }
  35.             catch (Exception ex)
  36.             {
  37.                 MessageBox.Show(ex.Message);
  38.             }
  39.         }
  40.  
  41.         private void registerBtn_Click(object sender, EventArgs e)
  42.         {
  43.             MySqlCommand command = new MySqlCommand("INSERT INTO users (username, password) VALUES ('" + usernameTxt.Text + "'," + "'" + passwordTxt.Text + "');", connection);
  44.             MySqlDataReader reader;
  45.             connection.Open();
  46.             reader = command.ExecuteReader();
  47.             while (reader.Read())
  48.             {
  49.             }
  50.             connection.Close();
  51.             MessageBox.Show("You are registred you can now log in!");
  52.         }
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement