• We just launched and are currently in beta. Join us as we build and grow the community.

Advertise Here

Advertise Here

Advertise Here

VB.NET Password Complexity

Deebee

URL Structure Specialist
D Rep
0
0
0
Rep
0
D Vouches
0
0
0
Vouches
0
Posts
119
Likes
168
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 100 XP
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:

passworddesign.png


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. ' Replace [A-Z] with \p{Lu}, to allow for Unicode uppercase letters.
  3. Dim

    upper As

    New

    System.

    Text

    .

    RegularExpressions

    .

    Regex

    (

    "[A-Z]"

    )
  4. Dim

    lower As

    New

    System.

    Text

    .

    RegularExpressions

    .

    Regex

    (

    "[a-z]"

    )
  5. Dim

    number As

    New

    System.

    Text

    .

    RegularExpressions

    .

    Regex

    (

    "[0-9]"

    )
  6. ' Special is "none of the above".
  7. Dim

    special As

    New

    System.

    Text

    .

    RegularExpressions

    .

    Regex

    (

    "[^a-zA-Z0-9]"

    )

  8. ' Check the length.
  9. If

    Len(

    pwd)

    <

    minLength Then

    Return

    False
  10. ' Check for minimum number of occurrences.
  11. If

    upper.

    Matches

    (

    pwd)

    .

    Count

    <

    numUpper Then

    Return

    False
  12. If

    lower.

    Matches

    (

    pwd)

    .

    Count

    <

    numLower Then

    Return

    False
  13. If

    number.

    Matches

    (

    pwd)

    .

    Count

    <

    numNumbers Then

    Return

    False
  14. If

    special.

    Matches

    (

    pwd)

    .

    Count

    <

    numSpecial Then

    Return

    False

  15. ' Passed all checks.
  16. Return

    True
  17. 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
passwordoutput1.png

A complex password
passwordoutput2_0.png


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


Download
You must upgrade your account or reply in the thread to view the hidden content.
 

452,498

348,335

348,344

Top