Passing value within form and function VB.NET 2003
-
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" ThenMe.Hide() Return (UserVerifySuccess = True) ' << I need to return this to my function. Thank you~! Else
-
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" ThenMe.Hide() Return (UserVerifySuccess = True) ' << I need to return this to my function. Thank you~! Else
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 )
-
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 )
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?