Thread: Login system

Results 1 to 5 of 5
  1. #1
    tomallall23's Avatar
    Join Date
    Nov 2017
    Gender
    male
    Posts
    8
    Reputation
    10
    Thanks
    0

    Lightbulb 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");
                }
            }
        }
    }
    Last edited by MikeRohsoft; 04-21-2019 at 04:36 AM. Reason: added code tags

  2. #2
    defaulto's Avatar
    Join Date
    Aug 2017
    Gender
    male
    Posts
    461
    Reputation
    427
    Thanks
    347
    My Mood
    Angelic
    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.

    #LOGS
    12-02-2020 ⌨ [MPGH]defaulto got gifted the Premium Membership from [MPGH]Azuki - sponsored by [MPGH]Flengo.
    27-11-2019 ⌨ [MPGH]defaulto captured the GFX Team Base together with [MPGH]Howl & [MPGH]Poonce.
    08-14-2017 ⌨ defaulto joined the game.

  3. #3
    Drunken Cheetahh's Avatar
    Join Date
    Apr 2019
    Gender
    male
    Posts
    13
    Reputation
    10
    Thanks
    0
    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.
    Last edited by Drunken Cheetahh; 04-27-2019 at 12:45 PM.

  4. #4
    univex's Avatar
    Join Date
    Apr 2012
    Gender
    male
    Posts
    284
    Reputation
    30
    Thanks
    1,952
    My Mood
    Busy
    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

  5. #5
    XoXlonG's Avatar
    Join Date
    Sep 2019
    Gender
    male
    Posts
    22
    Reputation
    10
    Thanks
    0
    Thanks for the useful information

Similar Threads

  1. *Tut* how to make a login system
    By u1111u in forum Programming Tutorials
    Replies: 13
    Last Post: 12-04-2009, 12:20 AM
  2. MySQL + VB.NET Login System
    By Marsicano in forum Visual Basic Programming
    Replies: 12
    Last Post: 10-16-2009, 06:46 AM
  3. A better Login System
    By Iamazn in forum Visual Basic Programming
    Replies: 6
    Last Post: 10-14-2009, 12:02 PM
  4. HOT![Tutorail!]Login system!+Video![Username and password!]
    By almog6666 in forum Visual Basic Programming
    Replies: 3
    Last Post: 04-27-2009, 05:31 PM
  5. My Login System(Flash)
    By radnomguywfq3 in forum General
    Replies: 13
    Last Post: 06-12-2008, 11:05 PM