Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Passing value within form and function VB.NET 2003

Passing value within form and function VB.NET 2003

Scheduled Pinned Locked Moved Visual Basic
csharpdatabasemysqlsecurity
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    drexler_kk
    wrote on last edited by
    #1

    Dear all, I have a problem with passing the return Boolean.This project is running with VB.NET 2003 with MySQL database. I'm using a Function to call a login verification as shown below:

    Public Function FurtherUser_Authenticate() As Boolean
    Dim FrmAuthen As New FrmAuthen
    FrmAuthen.StartPosition = FormStartPosition.CenterScreen
    FrmAuthen.Show()

    End Function

    And next I will prompup a form for the user to insert username and password for further verification. This will check the user login name and password from MySQL database for verification. After success verification I would like to return UserVerifySuccess = True to my function and the function will allowed the user to do some Setting on my window form application. The following are the code for loading of the FormSetting which need a further user verification to login because of security issues of the user:

    Private Sub FrmSetting1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    blnMustAuthenticate = True

    If blnMustAuthenticate Then
    UserVerifySuccess = False
    Me.Close()

         Further\_Authenticate()
            
            If UserVerifySuccess = True Then
                Me.Show()
            End If
    

    End If

    End Sub

    The code that used at FrmAuthen to check the user is allowed to do the setting is below:

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim x, pass As String
    Try
    ObjComm = New OdbcCommand("SELECT POS_CASHIER.LocationCode, CashierID, CashierName, Pwd, IF(POS_CASHIER.IsActive=1 AND POS_CASHIERGROUP.IsActive, 1, 0) AS IsActive, CanChangePwd, POS_CASHIER.GroupID, GroupName, IsFullAccess FROM POS_CASHIER INNER JOIN POS_CASHIERGROUP ON POS_CASHIER.GROUPID = POS_CASHIERGROUP.GROUPID AND POS_CASHIER.LocationCode = POS_CASHIERGROUP.LocationCode WHERE CashierID='" & TextBox1.Text & " ' ", ObjConn)
    ObjConn.Open()
    ObjRead = ObjComm.ExecuteReader
    If ObjRead.Read Then
    pass = ObjRead.Item(3)
    x = ObjRead.Item(8)
    ObjConn.Close()
    If TextBox2.Text = pass Then
    If x = "1" Then

                        Me.Hide()
                        Return (UserVerifySuccess = True)  ' << I need to return this to my function. Thank you~!
    
                    Else
    
    C 1 Reply Last reply
    0
    • D drexler_kk

      Dear all, I have a problem with passing the return Boolean.This project is running with VB.NET 2003 with MySQL database. I'm using a Function to call a login verification as shown below:

      Public Function FurtherUser_Authenticate() As Boolean
      Dim FrmAuthen As New FrmAuthen
      FrmAuthen.StartPosition = FormStartPosition.CenterScreen
      FrmAuthen.Show()

      End Function

      And next I will prompup a form for the user to insert username and password for further verification. This will check the user login name and password from MySQL database for verification. After success verification I would like to return UserVerifySuccess = True to my function and the function will allowed the user to do some Setting on my window form application. The following are the code for loading of the FormSetting which need a further user verification to login because of security issues of the user:

      Private Sub FrmSetting1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

      blnMustAuthenticate = True

      If blnMustAuthenticate Then
      UserVerifySuccess = False
      Me.Close()

           Further\_Authenticate()
              
              If UserVerifySuccess = True Then
                  Me.Show()
              End If
      

      End If

      End Sub

      The code that used at FrmAuthen to check the user is allowed to do the setting is below:

      Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
      Dim x, pass As String
      Try
      ObjComm = New OdbcCommand("SELECT POS_CASHIER.LocationCode, CashierID, CashierName, Pwd, IF(POS_CASHIER.IsActive=1 AND POS_CASHIERGROUP.IsActive, 1, 0) AS IsActive, CanChangePwd, POS_CASHIER.GroupID, GroupName, IsFullAccess FROM POS_CASHIER INNER JOIN POS_CASHIERGROUP ON POS_CASHIER.GROUPID = POS_CASHIERGROUP.GROUPID AND POS_CASHIER.LocationCode = POS_CASHIERGROUP.LocationCode WHERE CashierID='" & TextBox1.Text & " ' ", ObjConn)
      ObjConn.Open()
      ObjRead = ObjComm.ExecuteReader
      If ObjRead.Read Then
      pass = ObjRead.Item(3)
      x = ObjRead.Item(8)
      ObjConn.Close()
      If TextBox2.Text = pass Then
      If x = "1" Then

                          Me.Hide()
                          Return (UserVerifySuccess = True)  ' << I need to return this to my function. Thank you~!
      
                      Else
      
      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      drexler_kk wrote:

      Public Function FurtherUser_Authenticate() As Boolean Dim FrmAuthen As New FrmAuthen FrmAuthen.StartPosition = FormStartPosition.CenterScreen FrmAuthen.Show()End Function

      Well, this is obviously a disaster. Notice how your code doesn't return anything at all ? It's a travesty that this compiles. Also, when you call Show(), you get a modeless form. Your app has essentially shown a login form, but lost control of it at this point. It should use ShowDialog, then check the form to find out if login succeeded, and return a bool to indicate the result.

      drexler_kk wrote:

      ObjComm = New OdbcCommand("SELECT POS_CASHIER.LocationCode, CashierID, CashierName,.....

      First of all, read up on SQL injection. This code means I can erase your database, any time I like. Second, why is it all on one line ? I guess having a variable called TextBox1 is the point at which your code stands no chance of being readable, but still.....

      Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

      D 1 Reply Last reply
      0
      • C Christian Graus

        drexler_kk wrote:

        Public Function FurtherUser_Authenticate() As Boolean Dim FrmAuthen As New FrmAuthen FrmAuthen.StartPosition = FormStartPosition.CenterScreen FrmAuthen.Show()End Function

        Well, this is obviously a disaster. Notice how your code doesn't return anything at all ? It's a travesty that this compiles. Also, when you call Show(), you get a modeless form. Your app has essentially shown a login form, but lost control of it at this point. It should use ShowDialog, then check the form to find out if login succeeded, and return a bool to indicate the result.

        drexler_kk wrote:

        ObjComm = New OdbcCommand("SELECT POS_CASHIER.LocationCode, CashierID, CashierName,.....

        First of all, read up on SQL injection. This code means I can erase your database, any time I like. Second, why is it all on one line ? I guess having a variable called TextBox1 is the point at which your code stands no chance of being readable, but still.....

        Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

        D Offline
        D Offline
        drexler_kk
        wrote on last edited by
        #3

        Hello Mr. Christian Graus, I have try to change my code to the following:

        Public Function FurtherUser_Authenticate(ByVal UserVerifySuccess As Boolean) As Boolean
        Dim FrmAuthen As New FrmAuthen
        FrmAuthen.StartPosition = FormStartPosition.CenterScreen
        FrmAuthen.Show()

        End Function
        

        But I still found the error for my window frmSetting for the line of my function FurtherUser_Authenticate(). The error message appeared: Argument not specified for parameter 'UserVerifySuccess' of 'Public Function FurtherUser_Authenticate(UserVerifySuccess As Boolean As Boolean)'. Beside,can you give me some exaple how should I solve this problem here?

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups