Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Data;
- using System.Windows.Forms;
- using MySql.Data.MySqlClient;
- namespace MySql_Login_Form
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- MySqlConnection connection = new MySqlConnection("Server=sql7.freesqldatabase.com;Port=3306;Database=sql7111967;User Id=sql7111967;Password=P3gsMx3fZT;");
- MySqlDataAdapter adapter;
- DataTable table = new DataTable();
- private void loginBtn_Click(object sender, EventArgs e)
- {
- try
- {
- adapter = new MySqlDataAdapter("SELECT username, password FROM users WHERE username = '" + usernameTxt.Text + "' AND password = '" + passwordTxt.Text + "'", connection);
- adapter.Fill(table);
- if (table.Rows.Count >= 1)
- {
- MessageBox.Show("Login");
- }
- else
- {
- MessageBox.Show("False password or username");
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- }
- private void registerBtn_Click(object sender, EventArgs e)
- {
- MySqlCommand command = new MySqlCommand("INSERT INTO users (username, password) VALUES ('" + usernameTxt.Text + "'," + "'" + passwordTxt.Text + "');", connection);
- MySqlDataReader reader;
- connection.Open();
- reader = command.ExecuteReader();
- while (reader.Read())
- {
- }
- connection.Close();
- MessageBox.Show("You are registred you can now log in!");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement