dcsimg
Results 1 to 2 of 2

Thread: [2005] MySql Question

Threaded View

  1. #1

    Thread Starter
    Frenzied Member Motoxpro's Avatar
    Join Date
    Sep 2001
    Location
    Spiro, OK
    Posts
    1,211

    [2005] MySql Question

    had a question about security. Would it be bad for me to hard code the username and pw of my database and then check for the username and password in the database for the user to login. Here is my code. Right now its not complete but im just talking about the basic principal

    Code:
    'Dim Variables and set the connection string
            Dim conn As New MySqlConnection
            Dim ConnString As String
            Dim sqlCommand As New MySqlCommand
            Dim sqlReader As MySqlDataReader
    
            ConnString = "server=" & My.Settings.HostIP & ";" _
              & "username=Motoxpro;" _
              & "password=1234;" _
              & "database=scale"
            conn.ConnectionString = ConnString
    
            'Open a connection and check the database for the supplied username
            'And check if they are admin
            Try
                conn.Open()
                sqlCommand.Connection = conn
                sqlCommand.CommandText = "select username, admin from user u;"
                sqlReader = sqlCommand.ExecuteReader
    
                While sqlReader.Read
                    If sqlReader.GetString("username") = txtUserName.Text Then
                        If sqlReader.GetString("admin") = "1" Then
                            If MessageBox.Show("Would you like to login as an Admin?", "Admin Login", MessageBoxButtons.YesNoCancel, _
                            MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) = Windows.Forms.DialogResult.Yes Then
                                   frmAdmin.Show()
                            ElseIf Windows.Forms.DialogResult.No Then
                                 frmScale.Show()
                            Else
                                Exit Sub
                            End If
                        Else
                            frmScale.Show()
                        End If
                    End If
                End While
    
    
            Catch ex As MySqlException
                conn.Close()
                conn.Dispose()
                MessageBox.Show("Invalid login, Try again!", "Login")
                txtUserName.Focus()
            Finally
                conn.Close()
                conn.Dispose()
            End Try
    Last edited by Motoxpro; Oct 17th, 2007 at 06:26 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width