-
May 2nd, 2011, 07:29 AM
#1
VB6 login password
Dear VB gurus,
I'm using VB6 and SQL2005 Express.
I've a SQL table with 2 fields and records below:
UserName1 UCSIPassword1
--------------- ---------------------
z z
bird bird
abc abc
I've created a login VB6 interface, connected to the SQL and have put in
the correct data source and data field for the two text boxes. However,
with the following code, only first record can allow a login. Please advice what mistake
I have done in the coding:
Private Sub Form_Load()
Form6.txtUserName1.Text = ""
Form6.txtpw1.Text = ""
End Sub
Private Sub txtpw1_Change()
'Set cmdok1 as default after Password and UserName entered
cmdok1.Default = True
End Sub
Private Sub cmdok1_Click()
Dim Response As Integer
'Dim UserName As String
'Dim Password As String
If (txtUserName1.Text = Form7.DBpassword2.Recordset.Fields("UserName1")) Then
If (txtpw1.Text = Form7.DBpassword2.Recordset.Fields("UCSIPassword1")) Then
'Login Succeeded
Load Form3
Form3.Show
Unload Me
Else
'Wrong password cannot login to system
Response = MsgBox("Wrong password, try again!", vbOKOnly + vbCritical + vbApplicationModal, "System Security")
txtpw1.SetFocus
SendKeys "{Home}+{End}"
End If
Else
'Wrong UserName cannot login to system
Response = MsgBox("Wrong username, try again!", vbOKOnly + vbCritical + vbApplicationModal, "System Security")
txtUserName1.SetFocus
SendKeys "{Home}+{End}"
End If
End Sub
Thank you
-
May 2nd, 2011, 08:42 AM
#2
Re: VB6 login password
Loop through the record set until you find the correct username and then check the password...
Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
WPF Articles : 3D Animation 1 , 2 , 3
Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.
-
May 2nd, 2011, 09:01 AM
#3
Re: VB6 login password
Dear GremlinSA,
I'm not expert in programming & hv spent hours trying to correct this code.
Can you pls advice me where is the right place to put the Loop?
btw, do I need to include .MoveNext anywhere in the code to instruct the SQL pointer to
move to the next record? If yes, where is the right place to code it?
Your help is much appreciated. TQ.
-
May 2nd, 2011, 09:16 AM
#4
Re: VB6 login password
Code:
while not Form7.DBpassword2.Recordset.EOF
If (txtUserName1.Text = Form7.DBpassword2.Recordset.Fields("UserName1")) Then
If (txtpw1.Text = Form7.DBpassword2.Recordset.Fields("UCSIPassword1")) Then
'Login Succeeded
Load Form3
Form3.Show
Unload Me
Else
'Wrong password cannot login to system
Response = MsgBox("Wrong password, try again!", vbOKOnly + vbCritical + vbApplicationModal, "System Security")
txtpw1.SetFocus
SendKeys "{Home}+{End}"
End If
End If
Form7.DBpassword2.Recordset.movenext
Wend
Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
WPF Articles : 3D Animation 1 , 2 , 3
Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.
-
May 2nd, 2011, 10:07 AM
#5
Re: VB6 login password
Thanks for your reply. All usernames and passwords can log in now.
However, when a wrong password is used, the prompt message doesn't appear.
btw, how to also include the prompt message for wrong user name in the code.
Pls help. TQ.
-
May 2nd, 2011, 10:34 AM
#6
Re: VB6 login password
Okay, i got it!!! I just added .Refresh for both the Form Load and cmdok1_Click().
But now, where do I add in the wrong username prompt message into the code ?
Pls help. TQ.
Private Sub Form_Load()
Form7.DBpassword2.Refresh
Form6.txtUserName1.Text = ""
Form6.txtpw1.Text = ""
End Sub
Private Sub cmdok1_Click()
Form7.DBpassword2.Refresh
Dim Response As Integer
While Not Form7.DBpassword2.Recordset.EOF
If (txtUserName1.Text = Form7.DBpassword2.Recordset.Fields("UserName1")) Then
If (txtpw1.Text = Form7.DBpassword2.Recordset.Fields("UCSIPassword1")) Then
'Login Succeeded
Load Form3
Form3.Show
Unload Me
Else
'Wrong password cannot login to system
Response = MsgBox("Wrong password, try again!", vbOKOnly + vbCritical + vbApplicationModal, "System Security")
txtpw1.SetFocus
SendKeys "{Home}+{End}"
End If
End If
Form7.DBpassword2.Recordset.MoveNext
Wend
'If (txtpw1.Text <> Form7.DBpassword2.Recordset.Fields("UserName1")) Then
'Wrong UserName cannot login to system
'Response = MsgBox("Wrong username, try again!", vbOKOnly + vbCritical + vbApplicationModal, "System Security")
'txtUserName1.SetFocus
'SendKeys "{Home}+{End}"
'Form7.DBpassword2.Recordset.MoveNext
'End If
End Sub
-
May 2nd, 2011, 12:48 PM
#7
Re: VB6 login password
Better check your logic, and read it again...
Code:
'If (txtpw1.Text <> Form7.DBpassword2.Recordset.Fields("UserName1")) Then
if pw = un?
-
May 2nd, 2011, 01:14 PM
#8
Re: VB6 login password
Well if the user successfuly logs in we can add
Code:
Dim Logedin as Boolean
Code:
'Login Succeeded
Load Form3
Form3.Show
Unload Me
Logedin = true
Code:
If Not Logedin then
'invalid username
end if
Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
WPF Articles : 3D Animation 1 , 2 , 3
Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.
-
May 3rd, 2011, 01:12 AM
#9
Re: VB6 login password
Looping through the recordset will work but I would use a query by user id instead and then if found compare the password.
In a small database the looping method would be ok but in a very large one the query would be much faster.
Something like "Select UserPassword from tblUsers where UserID='" & txtUserID.Text & "'"
The recordset will be empty if a bad user name is given and will return the password if the correct username is entered, should be fast no matter if the database has 1 or 1,000,000 users
Always use [code][/code] tags when posting code.
-
May 3rd, 2011, 02:38 AM
#10
Re: VB6 login password
Originally Posted by DataMiser
Looping through the recordset will work but I would use a query by user id instead and then if found compare the password.
In a small database the looping method would be ok but in a very large one the query would be much faster.
Something like "Select UserPassword from tblUsers where UserID='" & txtUserID.Text & "'"
The recordset will be empty if a bad user name is given and will return the password if the correct username is entered, should be fast no matter if the database has 1 or 1,000,000 users
....
So true...
However looking at the posted code, It appeared that the OP is Using Bound data recordsets.. and not SQL queries.. Solution was provided that supports the Provided info...
I Too much prefer the SQL Query method...
Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
WPF Articles : 3D Animation 1 , 2 , 3
Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.
-
May 4th, 2011, 09:20 AM
#11
Re: VB6 login password
Thank you, VB gurus. Your advice has been helpful.
The While...Wend loop will make sure every data in database is checked.
I hv been trying to workout but I'm still having problems not sure where to place the wrong username prompt message. The idea is to show the user when a wrong password has been used and when a wrong username has been used.
Where do I best place this code below?
Else
'Wrong UserName cannot login to system
'Response = MsgBox("Wrong username, try again!", vbOKOnly + vbCritical + vbApplicationModal, "System Security")
'txtUserName1.SetFocus
'SendKeys "{Home}+{End}"
If I place it after the wrong password prompt message and within the While...Wend loop, it still gets messy.
Pls help. TQ
-
May 4th, 2011, 10:00 AM
#12
Re: VB6 login password
In that case, create a BOOLEAN variable that you can use in the WHILE LOOP.
Code:
While UserFound AND txtUser=...
then, when it is the wrong user, set UserFound to FALSE, and then you will exit the WHILE loop
-
May 4th, 2011, 01:30 PM
#13
Re: VB6 login password
Originally Posted by VirtualBaby
Thank you, VB gurus. Your advice has been helpful.
The While...Wend loop will make sure every data in database is checked.
I hv been trying to workout but I'm still having problems not sure where to place the wrong username prompt message. The idea is to show the user when a wrong password has been used and when a wrong username has been used.
Post #8 ...
Code:
Dim Logedin as Boolean
Code:
'Login Succeeded
Load Form3
Form3.Show
Unload Me
Logedin = true
Code:
If Not Logedin then
'invalid username
end if
But I guess i have to spoon feed...
Code:
Dim Logedin as Boolean
while not (Form7.DBpassword2.Recordset.EOF or Logedin)
If (txtUserName1.Text = Form7.DBpassword2.Recordset.Fields("UserName1")) Then
If (txtpw1.Text = Form7.DBpassword2.Recordset.Fields("UCSIPassword1")) Then
'Login Succeeded
Load Form3
Form3.Show
Unload Me
Logedin = true
Else
'Wrong password cannot login to system
Response = MsgBox("Wrong password, try again!", vbOKOnly + vbCritical + vbApplicationModal, "System Security")
txtpw1.SetFocus
SendKeys "{Home}+{End}"
End If
End If
Form7.DBpassword2.Recordset.movenext
Wend
If Not Logedin then
'Wrong UserName cannot login to system
Response = MsgBox("Wrong username, try again!", vbOKOnly + vbCritical + vbApplicationModal, "System Security")
txtUserName1.SetFocus
SendKeys "{Home}+{End}"
end if
Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
WPF Articles : 3D Animation 1 , 2 , 3
Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.
-
May 4th, 2011, 01:46 PM
#14
Re: VB6 login password
I would avoid the send keys and use the select methods instead
Code:
Text1.SelStart = 0
Text1.SelLength = Len(Text1.Text)
Always use [code][/code] tags when posting code.
-
May 7th, 2011, 08:32 AM
#15
Re: VB6 login password
Thank you, GremlinSA and Datamiser.
Now it works very well.
I have added 'Exit Sub' after the wrong password prompt message block.
Or else the wrong username msg will prompt after the wrong password prompt even though the correct username is used.
Learning is fun. TQ
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|