VB.NET Unclassified Check password strength

Source Code Snippet (edit)

Enum PasswordScore
	Blank = 0
	VeryWeak = 1
	Weak = 2
	Medium = 3
	Strong = 4
	VeryStrong = 5
End Enum

Public Class PasswordAdvisor

	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+") Then
			score = score + 1
		End If
		If Regex.IsMatch(password, "[a-z]") AndAlso Regex.IsMatch(password, "[A-Z]") Then
			score = score + 1
		End If
		If Regex.IsMatch(password, "[!@#\$%\^&\*\?_~\-\(\);\.\+:]+") Then
			score = score + 1
		End If

		Return CType(score, PasswordScore)

	End Function

End Class
    
comments powered by Disqus

Last Source Code Snippets in same category

VB.NET Add a network printer

VB.NET Unclassified2012-01-29 -

VB.NET Formatting a ten-digit phone number

VB.NET Unclassified2012-01-29 -

VB.NET Get Windows Experience Index base score for Vista

VB.NET Unclassified2012-01-29 -

VB.NET Only numeric values & maximium of 1 decimal point and one minus sign E

VB.NET Unclassified2012-01-29 -

VB.NET Safe execution of IDbCommand

VB.NET Unclassified2012-01-29 -

VB.NET Using TabIndex to load instructions to a StatusBar

VB.NET Unclassified2012-01-29 -