.NET Regular Expression to Create STRONG Password

Here is the .NET regular expression that I use to create a strong password (which is not true for my project password requirements):

(?=^.{15,25}$)(\d{2,}[a-z]{2,}[A-Z]{2,}[!@#$%&+~?]{2,})

Password Requirements:

  • Minimum 15 characters (up to 25)
  • Two numbers
  • Two uppercase letters
  • Two lowercase letters
  • Two special characters ! @ # $ % & + ~ ?

They don’t have to be next to each other and in a certain order, since the regular expression that I inserted is required.

The above regex requires a password similar to this: 12abCD! @QWertyP

He REQUIRES them in a specific order in RE ... this is not what I want!

This must pass a properly formatted RE with the above specifications: Qq1W! w2Ee # 3Rr4 @ Tt5

? , , .

+3
7

, , .

#/VB :

bool IsStrongPassword( String password )
{
    int upperCount = 0;
    int lowerCount = 0;
    int digitCount = 0;
    int symbolCount = 0;

    for ( int i = 0; i < password.Length; i++ )
    {
        if ( Char.IsUpper( password[ i ] ) )
            upperCount++;
        else if ( Char.IsLetter( password[ i ] ) )
            lowerCount++;
        else if ( Char.IsDigit( password[ i ] ) )
            digitCount++;
        else if ( Char.IsSymbol( password[ i ] ) )
            symbolCount++;
    }

    return password.Length >= 15 && upperCount >= 2 && lowerCount >= 2 && digitCount >= 2 && symbolCount >= 2;
}
+10

:

:

int count_alpha = 0, count_digit = 0, count_symbol = 0, ...

for each ch in password:
  if is_alpha(ch):
     count_alpha += 1
  elif is_digit(ch):
     count_digit += 1
  ...

if (count_alpha < 2) or (count_digit < 2) or ...
  rejection_message() 
  ...

, , , .

+3

, , , 24 .

4 :

  • \d{2,}
  • [a-z]{2,}
  • [a-z]{2,}
  • [!@#$%&+~?]{2,}

:

, , , , 3 , .

+2
^(?=.*\d.*\d)(?=.*[a-z].*[a-z])(?=.*[A-Z].*[A-Z])(?=.*[!@#$%&+~?].*[!@#$%&+~?]).{15,25}$

, . 5 , , , , , .

, .

+1

, :

(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[!@#$%&+~?])^.{15,25}$

, , .

, ?= .* (.. -), , , .

0

, , :

^ (? = (.\) {2}) (? = (. [AZ]) {2}) (? = (. [AZ]) {2}) (? = (. [@# $% &!? + ~].) {2})) {15,25} $

0
^((?=(.*\d){2,})(?=(.*[a-z]){2,})(?=(.*[A-Z]){2,})(?=(.*[!@#$%&+~?]){2,})).{15,25}$

, , , .

, , * .

0

Source: https://habr.com/ru/post/1718744/


All Articles