Package: task2b
Password generator v2.Module 2: Python. Task 2B.PrefaceThis project contains a solution to one of the tasks of the EPAM DevOps Initial Internal Training Course #7 in 2023.
Detailed information about the course, as well as reports on each of the completed tasks (including this one) can be foundhere.This project builds upontask #2Awith some modifications specific to this task condition. Please review thedocumentationto familiarize yourself with these changes. Below you will find additional information on the new features in task #2B.Table of ContentsTask descriptionDetailed conditionsPassword generation additional functionCode descriptionImplementationStructureInstallationShowcaseGeneral ProvisionsTask descriptionThe objective is to implement a password generator that returns whether a randomly generated password or password generated based on the passed template.
As part of this task, several features were added to a password generator that enables users to:use a space character as one of the symbols in a passworduse new placeholder '|' to randomly choose between two other placeholdersutilize new character set placeholdersDetailed conditionsPlease reviewmain conditionsfrom the task #2A.Password generation additional functionExpand the placeholders set.PlaceholderTypeCharacter SetaLower-Case Alphanumericabcdefghijklmnopqrstuvwxyz0123456789AMixed-Case AlphanumericABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789UUpper-Case AlphanumericABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789hLower-Case Hex Character0123456789abcdefHUpper-Case Hex Character0123456789ABCDEFvLower-Case VowelaeiouVMixed-Case VowelAEIOUaeiouZUpper-Case VowelAEIOUcLower-Case ConsonantbcdfghjklmnpqrstvwxyzCMixed-Case ConsonantBCDFGHJKLMNPQRSTVWXYZbcdfghjklmnpqrstvwxyzzUpper-Case ConsonantBCDFGHJKLMNPQRSTVWXYZbBracket()[]{}<>sPrintable 7-Bit Special Character!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~SPrintable 7-Bit ASCIIA-Z, a-z, 0-9, !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~xLatin-1 SupplementRange [U+00A1, U+00FF] except U+00AD: ¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ|Char Set or Char SetAllows you to randomly select one of two sets of characters to generateMore examples:dddddGenerates for example: 41922, 12733, 43960, 07660, 12390, 74680, ...\H\e\x:\ HHHHHHGenerates for example: 'Hex: 13567A', 'Hex: A6B99D', 'Hex: 02243C', ...Common password patterns:NamePatternHex Key - 40-BitH{10}Hex Key - 128-BitH{32}Hex Key - 256-BitH{64}MAC AddressHH-HH-HH-HH-HH-HHImportant! For all the following examples, you must enable the 'Randomly permute characters of password' option!RulePatternMust consist of 10 alphanumeric characters, where at least 2 are upper-case  letters and at least 2 are lower-case letters.uullA{6}Must consist of 9 characters of the set "ABCDEF" and an '@' symbol.\@[\A\B\C\D\E\F]{9}Code description* To better understand the gist, some segments of the actual code may be excluded or simplified in the following snippets.To meet the task conditions minor changes were made in the task #2A code.Utilization new character set placeholdersCHARACTER_SETS={'d':string.digits,# Digits'l':string.ascii_lowercase,# Small lateral ASCII'L':string.ascii_letters,# Mixed-case lateral ASCII'u':string.ascii_uppercase,# Big lateral ASCII'p':',.;:',}EXTENDED_CHARACTER_SETS={'a':string.ascii_lowercase+string.digits,'A':string.ascii_letters+string.digits,'U':string.ascii_uppercase+string.digits,'h':string.digits+'abcdef','H':string.digits+'ABCDEF','v':'aeiou','V':'AEIOUaeiou','Z':'AEIOU','c':'bcdfghjklmnpqrstvwxyz','C':'BCDFGHJKLMNPQRSTVWXYZbcdfghjklmnpqrstvwxyz','z':'BCDFGHJKLMNPQRSTVWXYZ','b':'()[]{}<>','s':'!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~','S':string.ascii_lowercase+string.ascii_uppercase+string.digits+'!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~','x':'¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ',}CHARACTER_SETS|=EXTENDED_CHARACTER_SETSUtilization a space character as one of the symbols in a password
Just one check condition was commented.defgenerate_password_from_pattern(pattern:str)->str:iftype(pattern)isnotstr:# Initial checkslogger.error(f'Incorrect pattern{pattern}. String expected.')return''elifnotpattern:logger.error(f'Pattern cannot be empty')return''# elif pattern.find(' ') != -1:#     logger.error(f'You cannot use space symbol in pattern ({pattern})')New code snippet was added to handle the placeholder '|' (to randomly choose between two other placeholders).# Multiply previous element while tuples present in the listifany(pat_ls)and(pat_ls[:1]=='|'orpat_ls[-1]=='|'):logger.error(f'The "|" placeholder is not allowed at the beginning or end of the pattern ({pattern}).')return''ifany([valforind,valinenumerate(pat_ls)ifval=='|'andind+1<len(pat_ls)andpat_ls[ind+1]=='|']):logger.error(f'The pattern ({pattern}) has an error as the "|" placeholder cannot go in a row.')return''# Let's proceed random selection between two placeholders via | (for instance, l|H or l|[daA])pat_ls=[random.choice([val,pat_ls[ind+2]])ifind+2<len(pat_ls)andpat_ls[ind+1]=='|'elsevalforind,valinenumerate(pat_ls)ifnot(val=='|'orpat_ls[ind-1]=='|')]# Replace placeholders to character setsFirst of all, additional checks were added. The | placeholder is not allowed to be placed at the start or end of the pattern,
because it must be situated between two placeholders to ensure random selection. Additionally, placing consecutive | placeholders is prohibited.
Following preliminary checks, three-placeholder sequences such as l|H or l|[daA] are proceeds in a pattern.
A single placeholder is selected randomly and replaces the three originally present.ImplementationPwgenis a Python package that could be added to your global or virtual environment by preferable package manager pip, pipenv, poetry, etc.
The project itself was managed and built using thePoetry library,
so if you intend to clone this repo and make some changes for your own purposes, please installPoetryor migrate to your preferred package management library.Based on the need to build and the possibility of using both the library and the CLI, the code was split into a library for importing and a script for execution
via the command line. Additionally, the package contains a showcase that demonstrates all use cases when run through the command line.To enhance the command line's functionality and expand showcase capabilities, theQuestionarylibrary is used and will be installed through a dependency link upon package installation.Structuretask_2b/
├── README.md (You are here now)
├── task_2b.toml # Poetry package management file
└── pwgen2/ (Module 1. Git)
    ├──__init__.py # library entry point
    ├──__main__.py # CLI entry point
    ├──__version__.py 
    ├── pwgen2.py # library implementation
    ├── cli/
    │   ├──__init__.py
    │   ├──__main__.py
    │   └── cli.py # CLI code implementation
    │
    └── showcase/
        ├──__init__.py 
        ├──__main__.py # showcase entry point when using python -m showcase
        ├── pattern-list.txt # input pattern examples file 
        ├── pattern-list-error.txt # input pattern examples file with intentional errors
        └── showcase.py # showcase implementationInstallationTo install pwgen2 packet please follow theinstructionfrom the previous task #2A. You should only change name of the packet fromtask2atotask2b.
Also, you should call nowpwgen2instead of pwgen andpwgen2_showcaseinstead of pwgen_showcase. Or if you need to invoke CLI or showcase from the module, invoke them
likepython -m pwgen2orpython3 -m pwgen2andpython -m pwgen2.showcaseorpython3 -m pwgen2.showcase.ShowcaseTo showcase the behavior of the pwgen library, an interactive command called "pwgen_showcase" has been created.
This command utilizes both the pwgen CLI and the pwgen library. It's an interactive command you can invoke viapwgen2_showcaseorpython -m pwgen2.showcaseorpython3 -m pwgen2.showcase.
It has an optional flag that allows you to view all use cases at once without any interaction.
You can use the commandpwgen2_showcase --allto activate this feature.A new part (special features pwgen ver.2), which includes additional use case examples, was added.
Additionally, the "pattern-list.txt" file was updated with new patterns.General provisionsAll materials provided and/or made available contain EPAM’s proprietary and confidential information and must not to be copied,
reproduced or disclosed to any third party or to any other person, other than those persons who have a bona fide need to review it
for the purpose of participation in the online courses being provided by EPAM.
The intellectual property rights in all materials (including any trademarks) are owned by EPAM Systems Inc or its associated companies,
and a limited license, terminable at the discretion of EPAM without notice, is hereby granted to you solely for the purpose of participating
in the online courses being provided by EPAM. Neither you nor any other party shall acquire any intellectual property rights of any kind
in such materials.