4/19/2013

Vb.Net Quick and Dirty Strong Password Checker

'1. Test each character in typed password
'2. Converter character into ASCII value and assign a score

 

Dim strtbpwd As String
Dim intpoints As Int16
Dim intasc2chr As Int16
btnchangepwd.Visible = False

strtbpwd = tbnewpwd.Text

If Len(strtbpwd) < 7 Then
intpoints = -10
End If
If Len(strtbpwd) >= 8 Then
intpoints = 2
End If
If Len(strtbpwd) >= 12 Then
intpoints = 3
End If

Do While Len(strtbpwd) > 0
intasc2chr = Asc(Left(strtbpwd, 1))
If intasc2chr > 32 And intasc2chr < 66 Then
intpoints = intpoints + 2
ElseIf intasc2chr > 64 And intasc2chr < 90 Then
intpoints = intpoints + 1
ElseIf intasc2chr > 122 Or intasc2chr < 31 Then
lblinfo.Text = "invalid character"
Exit Sub

End If

strtbpwd = Right(strtbpwd, Len(strtbpwd) - 1)
Loop

Select Case intpoints
Case Is <= 5
tossinfo("ERROR", "Bad Password; does not meet requirements. Try using numbers and symbols.")

Exit Sub
Case Is <= 6
tossinfo("INFO", "Acceptable Password - Re-type password into Confirm Password area and click Change Password.")
btnchangepwd.Visible = True
btnverifypwd.Visible = False
tbconfirmpwd.Visible = True
lblnewpwd.Visible = False

lblconfirm.Visible = True
Session.Add("svnewpass", tbnewpwd.Text)
tbnewpwd.Visible = False
Case Is <= 8
tossinfo("INFO", "Strong Password - Re-type password into Confirm Password area and click Change Password.")
btnchangepwd.Visible = True
btnverifypwd.Visible = False
tbconfirmpwd.Visible = True

lblnewpwd.Visible = False

lblconfirm.Visible = True
Session.Add("svnewpass", tbnewpwd.Text)
tbnewpwd.Visible = False
Case Is >= 10
tossinfo("INFO", "Very Strong Password - Re-type password into Confirm Password area and click Change Password.")
btnchangepwd.Visible = True
btnverifypwd.Visible = False

tbconfirmpwd.Visible = True
lblnewpwd.Visible = False

lblconfirm.Visible = True
Session.Add("svnewpass", tbnewpwd.Text)
tbnewpwd.Visible = False
End Select

No comments:

Post a Comment