i wanted know the vb.net code that checks the password strength on the basis of length ,special characters ,both combined ,numeric,alpha-numeric....

>>contents of form may include:
>textbox for password
>label or progress bar or trackbar to tell the user the strength(good ,very >good,excellent,poor)


>button to execute commands...

Recommended Answers

All 12 Replies

Member Avatar for Unhnd_Exception

Its up to you to decide on how strong a password is.

This will tell you how many uppercase, lowercase, numbers, and non numbers are in the password. You'll have to decide on what percentage of each is a strong password.

Dim t As String = "kaSDk43##$%43"

 Dim upper As Integer
 Dim lower As Integer
 Dim numbers As Integer
 Dim other As Integer

 For i = 0 To t.Length - 1

    If Char.IsLetter(t(i)) Then
        If Char.IsUpper(t(i)) Then
            upper += 1
        Else
            lower += 1
        End If

    ElseIf Char.IsNumber(t(i)) Then
        numbers += 1

    Else
        other += 1

    End If
Next

thank you..the code seems pretty easy...

i have a doubt ....how will this code take input from textbox....

I would use the _TextChanged Event.

Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
        Dim t As String = TextBox1.Text
        '// Remaining code here.
    End Sub

and the output if it should displayed in a label for example green for strong

and how to execute....cause theres no response for the event .the user should have an output

Its up to you to decide on how strong a password is.

This will tell you how many uppercase, lowercase, numbers, and non numbers are in the password. You'll have to decide on what percentage of each is a strong password.

No one can decide for you what a "strong" password is.

You could add all the numbers up and depending on the total, set the color of your Label.
Not a very good approach, but a start.

Here is a code sample with a slightly modified version of Unhnd_Exception's code.

Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
        Dim t As String = TextBox1.Text
        Dim iUpper, iLower, iNumbers, iOther As Integer
        For i As Integer = 0 To t.Length - 1 '// Loop thru all Characters in TextBox1.Text
            If Char.IsLetter(t(i)) Then
                If Char.IsUpper(t(i)) Then : iUpper += 2 '// 2 Points for UpperCase.
                Else : iLower += 1 '// 1 Point for LowerCase.
                End If
            ElseIf Char.IsNumber(t(i)) Then : iNumbers += 3 '// 3 Points for #'s.
            Else : iOther += 5 '// 5 Points for Special Charaters.
            End If
        Next

        Dim iSetTotal As Integer = iUpper + iLower + iNumbers + iOther '// sum Total.
        If iSetTotal <= 5 Then Label1.BackColor = Color.Red '// if Less than 6.
        If iSetTotal > 5 AndAlso iSetTotal <= 10 Then Label1.BackColor = Color.Orange '// if Greater than 5 and less that 11.
        If iSetTotal > 10 Then Label1.BackColor = Color.Green '// if Greater than 10.
    End Sub
Member Avatar for Unhnd_Exception

Heres a simple color meter control.

add a new new class to your project.

paste this into the new class.

rebuild the solution.

You should be able to drag and drop it from the
toolbox.

give it a value 0 - 100

Public Class Class1 : Inherits Control

Private _Value As Integer

Property Value() As Integer
    Get
       Return _Value
    End Get
    Set(ByVal value As Integer)
       If value < 0 Then value = 0
       If value > 100 Then value = 100
  
       _Value = value
       Me.Invalidate()
   End Set
End Property

Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
    Dim linBrush As New System.Drawing.Drawing2D.LinearGradientBrush(Me.ClientRectangle, Color.Empty, Color.Empty, Drawing2D.LinearGradientMode.Horizontal)
    Dim colBlend As New System.Drawing.Drawing2D.ColorBlend

    colBlend.Colors = New Color() {Color.Red, Color.Yellow, Color.Green}
    colBlend.Positions = New Single() {0, 0.5, 1}

    linBrush.InterpolationColors = colBlend

    e.Graphics.FillRectangle(linBrush, New Rectangle(0, 0, Me.Width * (_Value / 100), Me.Height))

    linBrush.Dispose()
End Sub

End Class
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.