Visual Basic .NET – Comprobar la fuerza de una contraseña (strong password)
Written by lopezatienza on 21/05/2011 – 00:19 -Buenas a todos.
Os muestro una función para comprobar la fuerza de una contraseña.
Se comprueba que la contraseña tenga una longitud de 8 caracteres, que al menos uno de ellos sea minúscula, una mayúscula, un número y un carácter especial:
Private Function IsStrongPassword(ByVal password As String) As Boolean
Dim upperCount As Integer = 0
Dim lowerCount As Integer = 0
Dim digitCount As Integer = 0
Dim symbolCount As Integer = 0
For i As Integer = 0 To password.Length - 1
If [Char].IsUpper(password(i)) Then
upperCount += 1
ElseIf [Char].IsLetter(password(i)) Then
lowerCount += 1
ElseIf [Char].IsDigit(password(i)) Then
digitCount += 1
ElseIf [Char].IsSymbol(password(i)) Then
symbolCount += 1
End If
Next
Return password.Length >= 8 AndAlso upperCount >= 1 AndAlso lowerCount >= 1 AndAlso digitCount >= 1 AndAlso symbolCount >= 1
End Function
Un saludo.
Autor: Antonio Lopez Atienza
Tags: VB.NET
Posted in Visual Basic .NET | 1 Comment »
