Solved

How do I create password/login file

Posted on 1998-10-22
2
135 Views
Last Modified: 2010-04-30
I'm new to Visual Basic and would like to know how to create a program that will allow a user three chances to enter a login+password. If login successful, then check password. If after three attempts login still invalid, then display a message.

I don't know much about Arrays, but I would like to use them to store 3 valid logins/passwords.

Hope somebody can help me out.
0
Comment
Question by:wdw1971
2 Comments
 
LVL 2

Accepted Solution

by:
Veroland earned 100 total points
ID: 1441093
create a form with 2 text boxes as and a commmand button. I named mine txtName and txtPassword. The command button is cmdSubmit.

Click on the password textbox and set the passwordchar property of the textbox to *.
Now use the following code and if the user enters a password it will be checked against a array holding 3 login names and passwords. If you want to load the Login Names and Passwords from a file or database let me know and I will post it for you. This exaple uses hard coded login names and passwords.

Option Explicit
Dim LoginPSW(3, 2) As String
Dim Counter As Integer
   

Private Sub cmdSubmit_Click()
    Dim I As Integer
    Dim Match As Boolean
       
    Match = False
    For I = 0 To UBound(LoginPSW)
        If txtName.Text = LoginPSW(I, 0) Then
            If txtPassword.Text = LoginPSW(I, 1) Then
                Match = True
            End If
        End If
    Next I
    If Match = False Then
        MsgBox "User Name not found or Inccorect password"
        Counter = Counter + 1
    End If
   
    If Match = False And Counter = 3 Then
        MsgBox "Program will Terminate"
        End
    End If
End Sub

Private Sub Form_Load()
    LoginPSW(0, 0) = "User1"
    LoginPSW(1, 0) = "User2"
    LoginPSW(2, 0) = "User3"
    LoginPSW(0, 1) = "Password"
    LoginPSW(1, 1) = "Voda"
    LoginPSW(2, 1) = "Earth"
    Counter = 0
   
End Sub

0
 

Author Comment

by:wdw1971
ID: 1441094
Many thanks for the help. It was very useful.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

758 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