-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
User and role bug fixed #435
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1038,31 +1038,47 @@ def validate_password(self, password, error_messages): | |
Returns: | ||
None: This function does not return a value, but it may append an error message to `error_messages` if the password is invalid. | ||
Criteria: | ||
- The password must be 8 to 20 characters long. | ||
- The password must be 9 to 20 characters long. | ||
- The password must include characters from at least three of the following classes: | ||
lowercase letters, uppercase letters, digits, and special characters. | ||
""" | ||
is_valid_password = False | ||
is_valid_password_check1 = False | ||
is_valid_password_check2 = False | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated the code accordingly. |
||
password_criteria_message = ( | ||
"Password must be 8 to 20 characters long and include characters from at least three of " | ||
"the following classes: lowercase letters, uppercase letters, digits, and special characters." | ||
"The password must be 9 to 20 characters long and include at least three of the following " | ||
"character types: lowercase letters, uppercase letters, digits, and special characters. " | ||
"Additionally, the password must not contain repetitive or sequential characters." | ||
) | ||
|
||
self.log(password_criteria_message, "DEBUG") | ||
password_regexs = [ | ||
re.compile(r'^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?!.*[\W_]).{8,20}$'), | ||
re.compile(r'^(?=.*[a-z])(?=.*[A-Z])(?=.*[\W_])(?!.*\d).{8,20}$'), | ||
re.compile(r'^(?=.*[a-z])(?=.*\d)(?=.*[\W_])(?!.*[A-Z]).{8,20}$'), | ||
re.compile(r'^(?=.*[A-Z])(?=.*\d)(?=.*[\W_])(?!.*[a-z]).{8,20}$'), | ||
re.compile(r'^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[\W_]).{8,20}$') | ||
re.compile(r'^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?!.*[\W_]).{9,20}$'), | ||
re.compile(r'^(?=.*[a-z])(?=.*[A-Z])(?=.*[\W_])(?!.*\d).{9,20}$'), | ||
re.compile(r'^(?=.*[a-z])(?=.*\d)(?=.*[\W_])(?!.*[A-Z]).{9,20}$'), | ||
re.compile(r'^(?=.*[A-Z])(?=.*\d)(?=.*[\W_])(?!.*[a-z]).{9,20}$'), | ||
re.compile(r'^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[\W_]).{9,20}$') | ||
] | ||
password_sequence_repetitive_regex = re.compile( | ||
r'^(?!.*(.)\1{3})' | ||
r'(?!.*(?:012|123|234|345|456|567|678|789|' | ||
r'abc|bcd|cde|def|efg|fgh|ghi|hij|ijk|jkl|klm|lmn|mno|nop|' | ||
r'opq|pqr|qrs|rst|stu|tuv|uvw|vwx|wxy|xyz|' | ||
r'ABC|BCD|CDE|DEF|EFG|FGH|GHI|HIJ|IJK|JKL|KLM|LMN|MNO|NOP|' | ||
r'OPQ|PQR|QRS|RST|STU|TUV|UVW|VWX|WXY|XYZ)).*' | ||
r'[a-zA-Z0-9!@#$%^&*()_+<>?]{9,20}$' | ||
) | ||
|
||
self.log("Checking that the password is 8 to 20 characters long and includes at least three character types.", "DEBUG") | ||
for password_regex in password_regexs: | ||
if password_regex.match(password): | ||
is_valid_password = True | ||
is_valid_password_check1 = True | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated the code accordingly. |
||
break | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated the code accordingly. |
||
if not is_valid_password: | ||
self.log("Checking that the password does not contain repetitive or sequential characters.", "DEBUG") | ||
if re.match(password_sequence_repetitive_regex, password): | ||
is_valid_password_check2 = True | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated the code accordingly. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also tested the changes Madhan |
||
|
||
if not is_valid_password_check1 or not is_valid_password_check2: | ||
self.log("Password validation failed: {0}".format(password_criteria_message), "DEBUG") | ||
error_messages.append(password_criteria_message) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated the code accordingly.