using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
using System.Windows.Forms.VisualStyles;
namespace Login
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void monoFlat_ThemeContainer1_Click(object sender, EventArgs e)
{
}
private void btnLogin_Click(object sender, EventArgs e)
{
string user = textUser.Text;
string pass = textPass.Text;
MySqlConnection conn = new MySqlConnection("server=sql2.freesqldatabase.com;user id=sql2288856;database=sql2288856");
MySqlDataAdapter sda = new MySqlDataAdapter("SELECT * FROM `mylogin` where username='" + textUser.Text + "' and password='" + textPass.Text + "'", conn);
DataTable dt = new DataTable();
sda.Fill(dt);
if (dt.Rows[0][0].ToString() == "1")
{
MessageBox.Show("Logged in!");
}
else
{
MessageBox.Show("incorrect username or pass");
}
}
}
}
Imports Mysql.Data.MySqlClient
Public Class LoginRegister
Private connect As New MySqlConnection("datasource=localhost;port=3306;username=root;password=;database=reporting")
ReadOnly Property getConnection() As MySqlConnection
Get
Return connect
End Get
End Property
Sub openConnection()
If connect.State = ConnectionState.Closed Then
connect.Open()
End If
End Sub
Sub closeConnection()
If connect.State = ConnectionState.Open Then
connect.Close()
End If
End Sub
End Class
If CheckBox1.Checked = True Then
My.Settings.username = TextBoxUsername.Text
My.Settings.RememberMe = True
My.Settings.Save()
My.Settings.Reload()
Else
My.Settings.username = ""
My.Settings.RememberMe = False
My.Settings.Save()
My.Settings.Reload()
End If
Dim connection As New LoginRegister
Dim adapter As New MySqlDataAdapter
Dim t As New DataTable
Dim command As New MySqlCommand("SELECT `username`, `pincode` FROM `users` WHERE `username` = @username AND `pincode`=@pass", connection.getConnection())
command.Parameters.Add( @username", MySqlDbType.VarChar).Value = TextBoxUsername.Text
command.Parameters.Add("@pass", MySqlDbType.VarChar).Value = TextBoxPin.Text
If TextBoxUsername.Text.Trim() = "" Or TextBoxPin.Text.Trim().ToLower() = "username" Then
MsgBox("Please enter a username to continue...", MsgBoxStyle.Exclamation, "Enter username")
ElseIf TextBoxPin.Text.Trim() = "" Or TextBoxPin.Text.Trim().ToLower() = "pincode" Then
MsgBox("Please enter a pincode to continue...", MsgBoxStyle.Exclamation, "Enter pincode")
Else
adapter.SelectCommand = command
adapter.Fill(t)
If t.Rows.Count > 0 Then
Me.Hide()
Dim main As New frmMain
main.Show()
Else
MsgBox("We couldn't locate an account with that username and/or password. Try again", MsgBoxStyle.Critical, "No Account Found")
End If
End If