LightbulbLogin system

Posts 15 of 5 · Page 1 of 1
Login system
Hi im trying to make a login form with user name and password, I opened a sql database server using this website freesqldatabase.com, I connected it to phpmyadmin, created tables... then I connected the visual studio into the server.
I always get this error: "MySql.Data.MySqlClient.MySqlException: 'Authentication to host 'sql2.freesqldatabase.com' for user 'sql2288856' using method 'mysql_native_password' failed with message: Access denied for user 'sql2288856'@'bzq-21-168-31-250.red.bezeqint.net' (using password: NO)'.
And this is my source code:
Code:
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");
            }
        }
    }
}
I am not sure here. Something is missing.

Quote Originally Posted by tomallall23 View Post
using password: NO
Can the password to the SQL-Database be ignored? I've never worked with SQL in C# yet. But going with that logic - everyone could connect to your SQL database as long they know the host and user of it, which would be fatal if you store private informations there that shouldn't be seen by others.

My guess is that you have to use a password. Or configure the Database so it works without one.
I would recommend using another mysql host.

I use vb.net (for personal projects) which connect to mysql server's including, localhost.
Maybe use localhost to test it all (if you haven't already) then once its all connected properly, find a mysql host.

Here is what I use for vb.net (if its any benefit to you)

Code:
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
Then when I click "Login" this is the code for that also,

Code:
 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
Hope this helps.
If you plan to distribute the application, meaning it's not just for your own use, you really shouldn't do MySQL operations on client side, it's huge security risk as everyone can just get your database information from the executable.

I'd recommend either PHP server in the middle or use some sort of TCP connection with solid encryption.


Have a nice day,
UniveX
Thanks for the useful information
Posts 15 of 5 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Need help?