Solved

Login Code

Posted on 2000-05-13
3
153 Views
Last Modified: 2010-05-02
This is probably a very simple problem,
but being a true novice to the VB programming I can't seem to get this to work.
I am trying to write a simple Login code. You type in a username & password
for validation. You have 3 chances to
get it right.If you type in the incorrect username or password a msgbox will say invalid. How can I get the code to allow 3 seperate passes and then a final msgbox saying Access denied
and end the program.
0
Comment
Question by:DavidTimonium
3 Comments
 
LVL 7

Expert Comment

by:Vbmaster
ID: 2807598
How about adding a private variable m_MissedPasses As Integer. In the login command button you put code to check if the password is correct, if it's not then add +1 to the m_MissedPasses variable. Then use code like...

   If (m_MissedPasses = 3) Then
      MsgBox "Stupid User did not enter correct Password"
      End
   End If

....to end the program.

Actually I would not use the End statement, but that's the easy way to do it. You should use Unload Me instead, but since I do not know what your program look like I can not say exactly how it should look like.
0
 
LVL 27

Accepted Solution

by:
Ark earned 50 total points
ID: 2807612
Hi
You start form code:
'Place 2 textboxes and two Commandbuttons on form

Dim CorrectPass As String, CorrectName As String
Dim bOK As Boolean

Private Sub Command1_Click()
  Static nCount As Integer
  If Text1 = "" Or Text2 = "" Then
     MsgBox "Enter UserName and Password!", vbOKOnly + vbExclamation
     Exit Sub
  End If
  nCount = nCount + 1
  If nCount > 2 Then End
  If Text1 = CorrectName And Text2 = CorrectPass Then bOK = True
  If bOK Then
     MsgBox "Correct!" & vbCrLf & "Press OK to continue", vbOKOnly
     End
  Else
     MsgBox "Incorrect!" & vbCrLf & "You have " & CStr(3 - nCount) & " more chance(s)", vbOKOnly
  End If
End Sub

Private Sub Command2_Click()
  End
End Sub

Private Sub Form_Load()
  bOK = False
  Caption = "Enter username and password"
  CorrectName = "Ark"
  CorrectPass = "DavidTimonium"
  Text1 = ""
  Text2 = ""
  Text1.PasswordChar = "*"
  Text2.PasswordChar = "*"
  Command1.Caption = "&Submit"
  Command2.Caption = "&Exit"
End Sub
0
 

Author Comment

by:DavidTimonium
ID: 2807660
Thanx Ark....It worked like a charm
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now