Click here to Skip to main content
Click here to Skip to main content

Validate password strength on the server side

, 9 Jan 2010
Rate this:
Please Sign up or sign in to vote.
This code will validate a password on the server side. ;) Imports System.Text.RegularExpressionsPublic Class PasswordAdvisor Enum PasswordScore Blank = 0 VeryWeak = 1 Weak = 2 Medium = 3 Strong = 4 VeryStrong = 5 End Enum ...
This code will validate a password on the server side. Wink | ;)
Imports System.Text.RegularExpressions
Public Class PasswordAdvisor
    Enum PasswordScore
        Blank = 0
        VeryWeak = 1
        Weak = 2
        Medium = 3
        Strong = 4
        VeryStrong = 5
    End Enum
    Public Shared Function CheckStrength(ByVal password As String) As PasswordScore
 
        Dim score As Int32 = 1
 
        If password.Length < 1 Then
            Return PasswordScore.Blank
        End If
 
        If password.Length < 4 Then
            Return PasswordScore.VeryWeak
        End If
 
        If password.Length >= 6 Then
            score = score + 1
        End If
        If password.Length >= 12 Then
            score = score + 1
        End If
        If Regex.IsMatch(password, "/\d+/", RegexOptions.ECMAScript) Then
            score = score + 1
        End If
        If Regex.IsMatch(password, "/[a-z]/", RegexOptions.ECMAScript AndAlso Regex.IsMatch(password, "/[A-Z]/", RegexOptions.ECMAScript)) Then
            score = score + 1
        End If
        If Regex.IsMatch(password, "/.[!,@,#,$,%,^,&,*,?,_,~,-,£,(,)]/", RegexOptions.ECMAScript) Then
            score = score + 1
        End If
 
        Return CType(score, PasswordScore)
 
    End Function
 
End Class

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Ehsan Valizadeh
-
Turkey Turkey
No Biography provided

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Mobile
Web01 | 2.8.140709.1 | Last Updated 9 Jan 2010
Article Copyright 2010 by Ehsan Valizadeh
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid