With Excel VBA, to loop through a text file containing usernames and passwords use the following code. It is probably a good idea to store encrypted passwords in the passwords file.
Dim FileNum as Integer
Dim UserName as String, UserPassword as String
FileNum=FreeFile
If Dir(ThisWorkbook.Path & Application.PathSeparator & “passwords.txt”) = “” Then
‘password file does not exist. Exit with Error
Msgbox “Password File Does not exist”
Else
Open ThisWorkbook.Path & Application.PathSeparator & “passwords.txt” For Input As FileNum
‘loop through passwords in the file till you find the one matching the client
Dim FoundPassword As Boolean
Dim UNameIter As String, PasswordIter As String ‘This is the values input by the user
LoginOK = False
While Not EOF(FileNum)
Input #FileNum, UNameIter, PasswordIter
If UNameIter = UserName Then
If PasswordIter=UserPassword Then
‘Login OK
LoginOK= True
End If
End If
Wend
If LoginOK= False Then
‘login not ok
Msgbox “User ID / Password do not match
Else
Msgbox “User ID and password are correct”
End If
End If
0 Responses
Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.