Password validation to accept both upper and lowercase text

Fmeister

Registered User.
Local time
Today, 20:01
Joined
Dec 21, 2010
Messages
45
On a form within excel, there is a textbox which allows the user to enter a password. This is then validated using a button which uses the If/Then statements. However, it is designed for the user to enter the password in lowercase. If the user enters it in uppercase or a mixture of both, the password is not validated.

I am looking for a code that will allow the user to be able to enter the password in either or a mixyure of both upper and lowercase.
 
How are you comparing the values? The normal operation of Access is case INSENSITIVE unless you specify Option Compare Binary instead of Option Compare Database in your module.
 
Private Sub btnOK_Click()
If CmbxUsername = "Farhan Choudry" And txtPassword = "password" Then
UserFormLogin.Hide
UserFormMenu.Show


ElseIf CmbxUsername = "Tim Cleary" And txtPassword = "password" Then
UserFormLogin.Hide
UserFormMenu.Show



Else
MsgBox ("INCORRECT LOGIN....please contact your administrator")
 
How are you comparing the values? The normal operation of Access is case INSENSITIVE unless you specify Option Compare Binary instead of Option Compare Database in your module.


It is VB within Excel
 
First off, make sure to use the user form name as well UserFormLogin.txtPassword instead of just txtPassword.

So revised code would be:

Code:
Dim strPwd As String
Dim strUser As String
Dim blnMatch As Boolean
 
strUser = UserFormLogin.CmbxUsername
strPwd = UserFormLogin..txtPassword
 
Select Case strUser
   Case "Farhan Choudry"
         blnMatch = (strComp(strPwd, "password", vbTextCompare) = 0)
   Case "Tim Cleary"
         blnMatch = (strComp(strPwd, "password", vbTextCompare) = 0)
End Select
 
If blnMatch Then
    UserFormLogin.Hide
    UserFormMenu.Show
Else
    MsgBox "INCORRECT LOGIN....please contact your administrator"
End If

Now I modified it to be a little less redundant. I assume that the two people don't have the same password and you just used the same as an example.
 
First off, make sure to use the user form name as well UserFormLogin.txtPassword instead of just txtPassword.

So revised code would be:

Code:
Dim strPwd As String
Dim strUser As String
Dim blnMatch As Boolean
 
strUser = UserFormLogin.CmbxUsername
strPwd = UserFormLogin..txtPassword
 
Select Case strUser
   Case "Farhan Choudry"
         blnMatch = (strComp(strPwd, "password", vbTextCompare) = 0)
   Case "Tim Cleary"
         blnMatch = (strComp(strPwd, "password", vbTextCompare) = 0)
End Select
 
If blnMatch Then
    UserFormLogin.Hide
    UserFormMenu.Show
Else
    MsgBox "INCORRECT LOGIN....please contact your administrator"
End If
Now I modified it to be a little less redundant. I assume that the two people don't have the same password and you just used the same as an example.

It has worked thank you very much.
I have difficulty in understanding why this code accepts both Uppers and Lowers. Also what are the "= 0)" for?
Thank you
 
Last edited:
I assume you are asking about this:
Code:
         blnMatch = (strComp(strPwd, "password", vbTextCompare) = 0)

That code basically says - set blnMatch to the value of this equation. And the equation is whether the two items both the string "password" and the text that was passed to strPwd from the text box match. strComp is a function that returns different values depending on if the strings match. And since we used Text Compare instead of Binary Compare it will match even if we are testing whether

password = PaSsWorD

etc.

And if it does match then strComp returns a 0. So, if strComp(..etc.) = 0 then it is True which sets the blnMatch to True. If the strComp function does not return a 0 then that statement is False
 
I assume you are asking about this:
Code:
         blnMatch = (strComp(strPwd, "password", vbTextCompare) = 0)
That code basically says - set blnMatch to the value of this equation. And the equation is whether the two items both the string "password" and the text that was passed to strPwd from the text box match. strComp is a function that returns different values depending on if the strings match. And since we used Text Compare instead of Binary Compare it will match even if we are testing whether

password = PaSsWorD

etc.

And if it does match then strComp returns a 0. So, if strComp(..etc.) = 0 then it is True which sets the blnMatch to True. If the strComp function does not return a 0 then that statement is False

As always, a wealth of info, Thank you so much!!!
 

Users who are viewing this thread

Back
Top Bottom