79435313

Date: 2025-02-13 07:10:33
Score: 1.5
Natty:
Report link

I am using Python to demonstrate the REGEX example using Python's re regex module to validate the password. :

Included in my solution, inserted in the regex pattern are the the old_password, username, and the word "password" for different letter case variations.

The solution matches with the requirements for the password:

PYTHON CODE:

import re

old_password = "Matilda#43555"

// # Collect username and password (defaults "matilda55577" and "HelloSunshine!456" respectively):
username = input("Username: ") or "matilda55577"
new_password = input("Password: ") or "HelloSunshine!456"

// # Insert username and password in the regex pattern: 
pattern = f"^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[#?!#@^*~+])(?!.*[pP][aA][sS][sS][wW][oO][rR][dD])(?!.*\.\w)(?!.*{username})(?!{old_password}$)" + ".{8,}$"
print(pattern)

pattern_re = re.compile(pattern)

for item in test_password_list: 
    print(item, end=": ")
    if pattern_re.match(item) == None:
        print("(---NOT VALID)")
    else:
        print("(---VALID)")

NOTES REGEX PATTERN:

pattern = f"^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[#?!#@^*~+])(?!.*[pP][aA][sS][sS][wW][oO][rR][dD])(?!.*\.\w)(?!.*{username})(?!{old_password}$)" + ".{8,}$"

ELEMENTS:

PATTERN STATEMENTS:


REGEX DEMO: https://regex101.com/r/XlyJNL/2


LIST OF TEST PASSWORDS:


test_password_list = [
new_password, 
old_password, 
username,
"Mother#234!",
"aaahelma!345",
"aaahElma!345",
"oldWorld#2222",
"77#elloYello!!!",
"Matilda#43555555",
"111matilda55577OK"
"1123444A!!!!!!!!",
"1123444A!!!!!Park!!",
"aaapasSword123#!KC",
"pASsWORd123#"
"4Matilda#43555234GGG",
"matilda55577!EFR444",
"maTmatilda55577!EFR444",
"hello.www.com.Park1!.com.youtube.com",
"https://stackoverflow.com/question/1234A!",
"ITs!stackoverflow123.com",
"ToSh4!",
"To2!",
"2!sH1",
"[email protected]",
"Matilda#43555",
"Matilda#435555"
]

RESULT:

Username:
Password:

^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[#?!#@^*~+])(?!.*[pP][aA][sS][sS][wW][oO][rR][dD])(?!.*\.\w)(?!.*matilda55577)(?!Matilda#43555$).{8,}$

HelloSunshine!456: (---VALID)
Matilda#43555: (---NOT VALID)
matilda55577: (---NOT VALID)
Mother#234!: (---VALID)
aaahelma!345: (---NOT VALID)
aaahElma!345: (---VALID)
oldWorld#2222: (---VALID)
77#elloYello!!!: (---VALID)
Matilda#43555555: (---VALID)
111matilda55577OK1123444A!!!!!!!!: (---NOT VALID)
1123444A!!!!!Park!!: (---VALID)
aaapasSword123#!KC: (---NOT VALID)
pASsWORd123#4Matilda#43555234GGG: (---NOT VALID)
matilda55577!EFR444: (---NOT VALID)
maTmatilda55577!EFR444: (---NOT VALID)
hello.www.com.Park1!.com.youtube.com: (---NOT VALID)
https://stackoverflow.com/question/1234A!: (---NOT VALID)
ITs!stackoverflow123.com: (---NOT VALID)
ToSh4!: (---NOT VALID)
To2!: (---NOT VALID)
2!sH1: (---NOT VALID)
[email protected]: (---NOT VALID)
Matilda#43555: (---NOT VALID)
Matilda#435555: (---VALID)
Reasons:
  • Blacklisted phrase (1): youtube.com
  • Blacklisted phrase (1): stackoverflow
  • Long answer (-1):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Low reputation (0.5):
Posted by: rich neadle