VB.NET Password Complexity

Strong passwords meet a number of requirements for complexity - including length and character categories - that make passwords more difficult for attackers to determine. Establishing strong password policies for your organization can help prevent attackers from impersonating users and can thereby help prevent the loss, exposure, or corruption of sensitive information. In this tutorial, we will create a program that can determine if the inputted password is complex or not :) Now, let's start this tutorial! 1. Let's start with creating a Windows Form Application for this tutorial by following the following steps in Microsoft Visual Studio: Go to File, click New Project, and choose Windows Application. 2. Next, add only one Button named Button1 and labeled it as "Submit" for determining the complexity of the password. Add one textbox named TextBox1 for inputting your desired password. Add two labels named Label1 labeled it as "Password is Complex:" and Label2 which is an empty string that has a boolean value for displaying the complexity. You must design your interface like this: design 3. Import System.text.RegularExpressions. We imported this namespace because it enables us to determine whether a particular string conforms to a regular expression pattern. 4. Create a function named ValidatePassword. Put this code in your code module:
  1.  Function ValidatePassword(ByVal pwd As String, Optional ByVal minLength As Integer = 8, Optional ByVal numUpper As Integer = 2, Optional ByVal numLower As Integer = 2, Optional ByVal numNumbers As Integer = 2, Optional ByVal numSpecial As Integer = 2) As Boolean
  2.  
  3.         ' Replace [A-Z] with \p{Lu}, to allow for Unicode uppercase letters.
  4.         Dim upper As New System.Text.RegularExpressions.Regex("[A-Z]")
  5.         Dim lower As New System.Text.RegularExpressions.Regex("[a-z]")
  6.         Dim number As New System.Text.RegularExpressions.Regex("[0-9]")
  7.         ' Special is "none of the above".
  8.         Dim special As New System.Text.RegularExpressions.Regex("[^a-zA-Z0-9]")
  9.  
  10.         ' Check the length.
  11.         If Len(pwd) < minLength Then Return False
  12.         ' Check for minimum number of occurrences.
  13.         If upper.Matches(pwd).Count < numUpper Then Return False
  14.         If lower.Matches(pwd).Count < numLower Then Return False
  15.         If number.Matches(pwd).Count < numNumbers Then Return False
  16.         If special.Matches(pwd).Count < numSpecial Then Return False
  17.  
  18.         ' Passed all checks.
  19.         Return True
  20.     End Function

Explanation

We have created ValidatePassword Function that has the following parameters of a password as string, minimum length of the password is 8, Capital Letter and Lower Letter must have a minimum of two letters, two digits of numbers, and must have a minimum of 2 special characters to make it complex. Then we have initialized variable upper to have capitalized letter, variable lower to have non-capitalized letter, variable number to have numerical inputs, and we used RegEx because it will hold the regular expression of not having a number or letter but to have a special character which it holds by variable special. Then it checks the length, if it will not have a minimum of 8 characters then it will return False as well as the other parameters. If it meets all the requirements, then it will display True. 5. Then, put this code to button1_click. This will display the output in boolean in Label2.
  1.  Label2.Text = ValidatePassword(TextBox1.Text)

Output:

Not a complex password output A complex password output Download the source code below and try it! :) For more inquiries and need programmer for your thesis systems in any kind of programming languages, just contact my number below. Best Regards,

Engr. Lyndon R. Bermoy
IT Instructor/System Developer/Android Developer
Mobile: 09079373999
Telephone: 826-9296
E-mail:[email protected]

Visit and like my page on Facebook at: Bermz ISware Solutions

Subscribe at my YouTube Channel at: SerBermz

Add new comment