Last active
August 22, 2020 18:40
-
-
Save rostyq/addc41e38dafad515f719ee615517571 to your computer and use it in GitHub Desktop.
python password generator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import string | |
import random | |
def generate(length=35, digits_count=5, upper_count=5, special_count=5): | |
lower_count = max(0, length - digits_count - upper_count - special_count) | |
digits = random.sample(string.digits, digits_count) | |
specials = random.sample(string.punctuation, special_count) | |
upper = random.sample(string.ascii_uppercase, upper_count) | |
lower = random.sample(string.ascii_lowercase, lower_count) | |
password = list(digits + upper + lower + specials) | |
random.shuffle(password) | |
return "".join(password) | |
def main(): | |
import argparse | |
parser = argparse.ArgumentParser(description='Password generator') | |
parser.add_argument("-l", '--length', type=int, default=35, | |
help='Password length.') | |
parser.add_argument("-d", '--digits_count', type=int, default=5, | |
help='Digits count.') | |
parser.add_argument("-u", '--upper_count', type=int, default=5, | |
help='Uppper characters count.') | |
parser.add_argument("-s", '--special_count', default=5, | |
type=int, help='Special characters count.') | |
args = parser.parse_args() | |
password = generate( | |
length=args.length, | |
digits_count=args.digits_count, | |
upper_count=args.upper_count, | |
special_count=args.special_count | |
) | |
print(password) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment