Distinguish Capital and small letter in password.

aman

Registered User.
Local time
Today, 06:28
Joined
Oct 16, 2008
Messages
1,251
Hi

I have written the following code to check for password before accessing the system. My problem is that it doesn't distinguish between capital and small letters. As my actual password is Aman123, If I type in the textbox aman123 then it again works but I dont want it to work if a person type small letter instead of capital letter.

Code:
Private Sub Command28_Click()

If IsNull(Text26.Value) Or Trim(Text26.Value) = "" Then
        MsgBox "User name or Password is incorrect or you may not have permissions to use this system.", vbCritical, "Access Denied"
        Text26.SetFocus
   End If
        
      
    
If DLookup("[UserPassword]", "tbluser", "UserName='" & Label25.Caption & "'") = Text26.Value Then
        
       Text26.Value = ""
      Label49.Visible = True
      Label50.Visible = True
    Else
        MsgBox "User name or Password is incorrect or you may not have permissions to use this system.", vbCritical, "Access Denied"
        Text26.SetFocus
    End If
End Sub

I hope anyone can help me in this.

Regards
Aman
 
Passwords should not be stored in their native text in the first place. They should be encrypted. Whats the use of having passwords in a table if someone can get access to the table.

Anyway if you retreive the data from the table first and pass it to a variable then compare it then you should get the exact match.

David
 
Hi David

I have set the input mask property to Password so the userpassword field of the table stores the values in *. But when I compare the actual password stored in the table field with textbox value then it doesn't check the small and capital letters and works fine. But I want it to differentiate between small and capital letters.
I have changed my code and retrieved the data from a table and stored in a variable. When I compare the variable value with the textbox value then it again doesn't work.
Code:
If IsNull(Text26.Value) Or Trim(Text26.Value) = "" Then
        MsgBox "User name or Password is incorrect or you may not have permissions to use this system.", vbCritical, "Access Denied"
        Text26.SetFocus
   End If
        Dim a As String
    a = DLookup("[UserPassword]", "tbluser", "UserName='" & Label25.Caption & "'")
        
If a = Text26.Value Then
        
       Text26.Value = ""
      Label49.Visible = True
      Label50.Visible = True
    Else
        MsgBox "User name or Password is incorrect or you may not have permissions to use this system.", vbCritical, "Access Denied"
        Text26.SetFocus
    End If

Thanks
Aman
 
If you ad "Option Compare Binary" to your code it will work.
 
Thanks a lot Peter. It worked perfectly.

Cheers
 
Setting the input mask to password is totally useless for security reasons. Anyone can import the table and change the input mask or even change the original table input format.

David
 
hi
after deep thinking, I finally write the following code to request the user to enter password with upper and lower case letter plus one number at least

here is the code:
record goes to me :cool:
the following code should be pasted in txtbox after update case

Code:
Private Sub Password_AfterUpdate()
' written by EMAD

    If IsNull(Me.Password) Then
        Me.Password.Value = "password"
        MsgBox "password must contain at least 8 characters, password will be reset to password", vbOKOnly
    Exit Sub
    End If
On Error GoTo error





    If Len(Me.Password) < 8 Then
        Me.Password.Value = "password"
        MsgBox "password must contain at least 8 characters, password will be reset to password", vbOKOnly
    Exit Sub
    End If

Dim N0, N1, N2, N3, N4, N5, N6, N7, N8, N9 As String
N0 = InStr(Me.Password, "0")
N1 = InStr(Me.Password, "1")
N2 = InStr(Me.Password, "2")
N3 = InStr(Me.Password, "3")
N4 = InStr(Me.Password, "4")
N5 = InStr(Me.Password, "5")
N6 = InStr(Me.Password, "6")
N7 = InStr(Me.Password, "7")
N8 = InStr(Me.Password, "8")
N9 = InStr(Me.Password, "9")

If (N0 + N1 + N2 + N3 + N4 + N5 + N6 + N7 + N8 + N9) = 0 Then
        Me.Password.Value = "password"
        MsgBox "password must contain at least one numeric value, password will be reset to password", vbOKOnly
    Exit Sub
    End If
    
Dim CA, CB, CC, CD, CE, CF, CG, CH, CI, CJ, CK, CL, CM, CN, CO, CP, CQ, CR, CS, CT, CU, CV, CW, CX, CY, CZ As String

    CA = InStr(Me.Password, "A")
    CB = InStr(Me.Password, "B")
    CC = InStr(Me.Password, "C")
    CD = InStr(Me.Password, "D")
    CE = InStr(Me.Password, "E")
    CF = InStr(Me.Password, "F")
    CG = InStr(Me.Password, "G")
    CH = InStr(Me.Password, "H")
    CI = InStr(Me.Password, "I")
    CJ = InStr(Me.Password, "J")
    CK = InStr(Me.Password, "K")
    CL = InStr(Me.Password, "L")
    CM = InStr(Me.Password, "M")
    CN = InStr(Me.Password, "N")
    CO = InStr(Me.Password, "O")
    CP = InStr(Me.Password, "P")
    CQ = InStr(Me.Password, "Q")
    CR = InStr(Me.Password, "R")
    CS = InStr(Me.Password, "S")
    CT = InStr(Me.Password, "T")
    CU = InStr(Me.Password, "U")
    CV = InStr(Me.Password, "V")
    CW = InStr(Me.Password, "W")
    CX = InStr(Me.Password, "X")
    CY = InStr(Me.Password, "Y")
    CZ = InStr(Me.Password, "Z")

If (CA + CB + CC + CD + CE + CF + CG + CH + CI + CJ + CK + CL + CM + CN + CO + CP + CQ + CR + CS + CT + CU + CV + CW + CX + CY + CZ) = 0 Then
    Me.Password.Value = "password"
    MsgBox "Password must contain at least one upper letter,password reset to password", vbOKOnly
    Exit Sub
End If


Dim Sa, Sb, Sc, Sd, Se, Sf, Sg, Sh, Si, Sj, Sk, Sl, Sm, Sn, So, Sp, Sq, Sr, Ss, St, Su, Sv, Sw, Sx, Sy, Sz As String

    Sa = InStr(Me.Password, "a")
    Sb = InStr(Me.Password, "b")
    Sc = InStr(Me.Password, "c")
    Sd = InStr(Me.Password, "d")
    Se = InStr(Me.Password, "e")
    Sf = InStr(Me.Password, "f")
    Sg = InStr(Me.Password, "g")
    Sh = InStr(Me.Password, "h")
    Si = InStr(Me.Password, "i")
    Sj = InStr(Me.Password, "j")
    Sk = InStr(Me.Password, "k")
    Sl = InStr(Me.Password, "l")
    Sm = InStr(Me.Password, "m")
    Sn = InStr(Me.Password, "n")
    So = InStr(Me.Password, "o")
    Sp = InStr(Me.Password, "p")
    Sq = InStr(Me.Password, "q")
    Sr = InStr(Me.Password, "r")
    Ss = InStr(Me.Password, "s")
    St = InStr(Me.Password, "t")
    Su = InStr(Me.Password, "u")
    Sv = InStr(Me.Password, "v")
    Sw = InStr(Me.Password, "w")
    Sx = InStr(Me.Password, "x")
    Sy = InStr(Me.Password, "y")
    Sz = InStr(Me.Password, "z")

If (Sa + Sb + Sc + Sd + Se + Sf + Sg + Sh + Si + Sj + Sk + Sl + Sm + Sn + So + Sp + Sq + Sr + Ss + St + Su + Sv + Sw + Sx + Sy + Sz) = 0 Then
    Me.Password.Value = "password"
    MsgBox "Password must contain at least one lower letter,password reset to password", vbOKOnly
    Exit Sub
End If
error:



End Sub
 

Users who are viewing this thread

Back
Top Bottom