Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using MySql.Data.MySqlClient;
- namespace ECBSRecruitmentAgencySoftware
- {
- public partial class LogIn : Form
- {
- public LogIn()
- {
- InitializeComponent();
- }
- public bool tryLogin(string username, string password)
- {
- MySqlConnection con = new MySqlConnection("host=think-tek.net;user=ctutorial;password=chang3d;database=ctutorial_logintest;");
- MySqlCommand cmd = new MySqlCommand("Select * FROM login WHERE user_name = `" + username + "` AND user_pass = `" + password + "`;");
- cmd.Connection = con;
- con.Open();
- MySqlDataReader reader = cmd.ExecuteReader();
- if (reader.Read() != false)
- {
- if (reader.IsDBNull(0) == true)
- {
- cmd.Connection.Close();
- reader.Dispose();
- cmd.Dispose();
- return false;
- }
- else
- {
- cmd.Connection.Close();
- reader.Dispose();
- cmd.Dispose();
- return true;
- }
- }
- else
- {
- return false;
- }
- }
- private void button1_Click(object sender, EventArgs e)
- {
- if (tryLogin(textBox1.Text, textBox2.Text) == true)
- {
- MainScreen F2 = new MainScreen();
- F2.Show();
- this.Hide();
- }
- else MessageBox.Show("Wrong details!");
- }
- }
- }
- string mySqlConn = "server=localhost;user=username;database=databasename;port=3306;password=password;";
- public bool tryLogin(string username, string password)
- {
- MySqlConnection con = new MySqlConnection("SERVER=localhost;" +
- "DATABASE=mydatabase;" +
- "UID=testuser;" +
- "PASSWORD=testpassword;");
- MySqlCommand cmd = new MySqlCommand("Select * FROM login WHERE user_name = `" + username + "` AND user_pass = `" + password + "`;");
- cmd.Connection = con;
- con.Open();
- MySqlDataReader reader = cmd.ExecuteReader();
- if (reader.Read() != false)
- {
- if (reader.IsDBNull(0) == true)
- {
- cmd.Connection.Close();
- reader.Dispose();
- cmd.Dispose();
- return false;
- }
- else
- {
- cmd.Connection.Close();
- reader.Dispose();
- cmd.Dispose();
- return true;
- }
- }
- else
- {
- return false;
- }
- }
- string connection = "server=localhost;database=student_record_database;user=root;password=;";
- MySqlConnection con = new MySqlConnection(connection);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement