Re: lower/upper case in password (1 Viewer)

alicejwz

Registered User.
Local time
Today, 08:09
Joined
Jul 9, 2003
Messages
91
Re: lower/upper case in password

Hi all,

I have two text boxes where user type in their password. First they type in their password in text box one then they need to type in second text box to verify with the first one. No problem there. But when I try to compare two password fields one has a lower case the other is in upper case it returns as a match.
ex:
If Me!passwd.Value = Me!passwd_retype.Value Then
Debug.Print Me!passwd.Value, Me!passwd_retype.Value
m*m) M*M)

I want it to return Not a match when lower or upper case don't match.

What do I need in the code or perhaps in property setting?
I'm using AC2K.

Thanks for your input.
 

ghudson

Registered User.
Local time
Today, 04:09
Joined
Jun 8, 2002
Messages
6,195
I saw this somewhere before but I do not remember the answer. I think you have to compare the ASCII value or something like that. Maybe that will spark somebody else to remember how to do it.
 

FoFa

Registered User.
Local time
Today, 03:09
Joined
Jan 29, 2003
Messages
3,672
You could a function something like this:
It returns true or false, you feed the two to compare:

Code:
Function CharCompare(Word1 as string, Word2 as string) as boolean
dim C1 as int, C2 as int, LP as int
If Len(Word1) <> Len(Word2) then 
 CharCompare = false
 exit function
End If
For LP = 1 to len(Word1)
 C1 = ASC(mid(Word1,LP,1))
 C2 = ASC(mid(Word2,LP,1))
 If C1 <> C2 Then
  CharCompare = false
  exit function
 End If
Next LP
CharCompare = true
End Function
 

ghudson

Registered User.
Local time
Today, 04:09
Joined
Jun 8, 2002
Messages
6,195
That is it. Nice job FoFa!
Code:
Public Sub Test()

    If CharCompare("TESTing123", "TESTING123") = True Then
        MsgBox "True"
    Else
        MsgBox "False"
    End If

End Sub

Public Function CharCompare(Word1 As String, Word2 As String) As Boolean

    Dim C1 As Integer
    Dim C2 As Integer
    Dim LP As Integer
    
    If Len(Word1) <> Len(Word2) Then
        CharCompare = False
        Exit Function
    End If
    
    For LP = 1 To Len(Word1)
        C1 = Asc(Mid(Word1, LP, 1))
        C2 = Asc(Mid(Word2, LP, 1))
    If C1 <> C2 Then
        CharCompare = False
        Exit Function
    End If
    
    Next LP
    
    CharCompare = True
    
End Function
 

alicejwz

Registered User.
Local time
Today, 08:09
Joined
Jul 9, 2003
Messages
91
Re: lower/upper case in password

Thank you Ghudson!
Thank you Fofa!
That's what I'm looking for.
 

ChrisO

Registered User.
Local time
Today, 19:09
Joined
Apr 30, 2003
Messages
3,202
Another method: -

Code:
Option Compare Database
Option Explicit


Public Sub Test()
    
    If StrComp("TESTing123", "TESTING123", vbBinaryCompare) = 0 Then
        MsgBox "True"
    Else
        MsgBox "False"
    End If

End Sub
Hope that helps.

Regards,
Chris.
 

ChrisO

Registered User.
Local time
Today, 19:09
Joined
Apr 30, 2003
Messages
3,202
You’re welcome but initially I couldn’t think of the function just the compare binary flag.

You might like Traps with the compare.

Edit to add…
And that is why my posts have always changed Option Compare Database to Option Compare Text in the last few years…it just ain’t worth the risk.
But in my last post I did test it that way just to prove the local constant to the procedure, vbBinaryCompare, overrides the default.

Regards,
Chris.
 
Last edited:

emad258

New member
Local time
Today, 10:09
Joined
Aug 31, 2016
Messages
8
Re: lower/upper case in password

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
 

plog

Banishment Pending
Local time
Today, 03:09
Joined
May 11, 2011
Messages
11,613
Re: lower/upper case in password

Deep thinking for 11 years?
 

ButtonMoon

Registered User.
Local time
Today, 08:09
Joined
Jun 4, 2012
Messages
304
Re: lower/upper case in password

Here's a slightly more compact way of doing these comparisons:

Code:
If Not password Like "*[0-9]*" Then
    err = err + "Password must contain at least one numeric character" + Chr(13)
End If

If StrComp(password, LCase(password), vbBinaryCompare) = 0 Then
    err = err + "Password must contain at least one upper case character" + Chr(13)
End If

If StrComp(password, UCase(password), vbBinaryCompare) = 0 Then
    err = err + "Password must contain at least one lower case character" + Chr(13)
End If

If Len(err) > 1 Then
    MsgBox err
End If
However, password entry and checking in Windows forms is a dire thing to do and something to be avoided at all costs. When this thread began eleven years ago you might just have got away with it. These days single sign-on is almost an entry-level requirement and passwords in a desktop app are pretty unacceptable IMHO.
 
Last edited:

Users who are viewing this thread

Top Bottom