|
-
Apr 5th, 2007, 11:19 AM
#1
Thread Starter
Frenzied Member
[RESOLVED] password problem
I have a problem.Actually I want to set a counter that allow the user to enter the valid password for 3 times.. if the password fail after 3 times attempt, the form 1 show.How to do that?
Code:
Set adoConn = New ADODB.Connection
Set adoRS = New ADODB.Recordset
Dim cs As String
cs = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\AdminPassword.mdb" & ";Persist Security Info=False;"
adoConn.ConnectionString = cs
adoConn.Open
If Text2.Text = "" Then
MsgBox "Sila masukkan Kata laluan Anda", vbCritical, "Kata laluan"
' MsgBox "Sila masukkan Kata laluan Anda"
Text2.Text = ""
Text2.SetFocus
Else
usrnm = Text2.Text
adoRS.Open "SELECT * FROM pass WHERE password='" & usrnm & "';", adoConn, adOpenStatic, adLockOptimistic
If adoRS.Fields("Password").Value = Text2.Text Then
pass = True
'if password valid, success
MsgBox "Anda Berjaya memasuki ruang admin" & vbCrLf & "Logged in. Username: " & usrnm & " !", vbInformation, "Selamat datang"
Form2.Show
Unload Me
Else
'if password invalid,message box ask to insert invalid password
MsgBox "Kata laluang tidah sah. Ruang ini hanya untuk admin", vbCritical, "WARNING"
'Exit Sub
Unload Me
Form1.Show
Exit Sub
End If
End If
End Sub
-
Apr 5th, 2007, 11:44 AM
#2
Re: password problem
Something like
vb Code:
Dim intCounter As Integer
Set adoConn = New ADODB.Connection
Set adoRS = New ADODB.Recordset
Dim cs As String
cs = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\AdminPassword.mdb" & ";Persist Security Info=False;"
adoConn.ConnectionString = cs
adoConn.Open
If Text2.Text = "" Then
MsgBox "Sila masukkan Kata laluan Anda", vbCritical, "Kata laluan"
' MsgBox "Sila masukkan Kata laluan Anda"
Text2.Text = ""
Text2.SetFocus
Else
usrnm = Text2.Text
adoRS.Open "SELECT password FROM pass WHERE password='" & usrnm & "';", adoConn, adOpenStatic
If adoRS.Fields("Password").Value = Text2.Text Then
pass = True
'if password valid, success
MsgBox "Anda Berjaya memasuki ruang admin" & vbCrLf & "Logged in. Username: " & usrnm & " !", vbInformation, "Selamat datang"
Form2.Show
Else
intCounter = intCounter + 1
If intCounter = 3 Then
Form1.Show
Else
Msgbox "Invalid Password"
End If
End If
-
Apr 5th, 2007, 12:08 PM
#3
Thread Starter
Frenzied Member
Re: password problem
The counter value did not change. The value does not increase. It still start with 0 value.
Code:
If adoRS.Fields("Password").Value = Text2.Text Then
pass = True
'if password valid, success
MsgBox "Anda Berjaya memasuki ruang admin" & vbCrLf & "Logged in. Username: " & usrnm & " !", vbInformation, "Selamat datang"
frmmanagement.Show
Unload Me
Else
intCounter = intCounter + 1
If intCounter = 3 Then
frmMenu.Show
Unload Me
Else
'if password invalid,message box ask to insert invalid password
MsgBox "Invalid password", vbCritical, "WARNING"
Text2.Text = ""
Text2.SetFocus
End If
End If
-
Apr 5th, 2007, 12:15 PM
#4
Re: password problem
If the first part of your code works (which I did not test) that would tell me the password was valid.
-
Apr 5th, 2007, 12:21 PM
#5
Thread Starter
Frenzied Member
Re: password problem
Yes. But if the password invalid, it go to the second part. at the second part, the user are allow enter the password for 3 times.After 3 attempt,If the password invalid the frmMenu will appear
Code:
intCounter = intCounter + 1
If intCounter = 3 Then
frmMenu.Show
Unload Me
Else
'if password invalid,message box ask to insert invalid password
MsgBox "Invalid password", vbCritical, "WARNING"
Text2.Text = ""
Text2.SetFocus
End If
-
Apr 5th, 2007, 12:31 PM
#6
Re: password problem
If you are doing this all in a button click, then you are resetting the counter each time you click it. Take Dim intCounter As Integer and move it the forms declaration section and declare it as Private.
Last edited by Hack; Apr 5th, 2007 at 01:08 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|