Android Code Snippet [B4X] Validate Password strength

This is a port from this VB.NET code.
B4X:
Private Sub ValidatePassword(pwd As String,minLength As Int,numUpper As Int,numLower As Int,numNumbers As Int,numSpecial As Int) As Boolean   
    If pwd.Length < minLength Then Return False
    If CountMatches(pwd,"[A-Z]") < numUpper Then Return False
    If CountMatches(pwd,"[a-z]") < numLower Then Return False
    If CountMatches(pwd,"[0-9]") < numNumbers Then Return False
    If CountMatches(pwd,"[^a-zA-Z0-9]") < numSpecial Then Return False
    ' Passed all checks.
    Return True   
End Sub
CountMatches you can find here.

Example:
If ValidatePassword("Willkommen2020!",8,1,1,1,1) = True Then
        Log("Password is ok")
    Else
        Log("Password is not ok")
    End If
 
Top