Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,907 questions

51,839 answers

573 users

How to check whether a given password is strong, medium, or weak in VB.NET

1 Answer

0 votes
Imports System

' You can set your own rules

Public Class PasswordStrengthChecker_VB_NET
    Public Shared Function checkPasswordStrength(ByVal password As String) As String
        Dim length As Integer = password.Length
        Dim hasLower As Boolean = False, hasUpper As Boolean = False
        Dim hasDigit As Boolean = False, specialChar As Boolean = False
        Dim lowuppdig As String = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"

        For i As Integer = 0 To length - 1
            If Char.IsLower(password(i)) Then
                hasLower = True
            End If
            If Char.IsUpper(password(i)) Then
                hasUpper = True
            End If
            If Char.IsDigit(password(i)) Then
                hasDigit = True
            End If
            If lowuppdig.IndexOf(password(i)) = -1 Then
                specialChar = True
            End If
        Next

        If hasLower AndAlso hasUpper AndAlso hasDigit AndAlso specialChar AndAlso length >= 10 Then
            Return "Strong"
        ElseIf (hasLower OrElse hasUpper) AndAlso specialChar AndAlso length >= 8 Then
            Return "Medium"
        End If

        Return "Weak"
    End Function

    Public Shared Sub Main(ByVal args As String())
        Dim password As String = "aq1o@p9$XM"
	
        Console.WriteLine(checkPasswordStrength(password))
        Console.WriteLine(checkPasswordStrength("asW!W)(o"))
        Console.WriteLine(checkPasswordStrength("WSDFK!#Q"))
        Console.WriteLine(checkPasswordStrength("n*djskq*"))
        Console.WriteLine(checkPasswordStrength("WE3q#$"))
    End Sub
End Class



' run:
'
' Strong
' Medium
' Medium
' Medium
' Weak
' 

 



answered Oct 22, 2024 by avibootz
...