Python Forum

Full Version: mkpw: rewriting in python 3
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Well, here is a something small:

import click
from string import ascii_letters, digits, punctuation
from random import SystemRandom

@click.command()
@click.argument('length', default=8, nargs=1, type=int)
@click.argument('char_set', default='anum', type=click.Choice(['alfa', 'num', 'anum', 'all']))
@click.argument('additional', default="", type=str)
def gen_pass(length, char_set, additional):
    chars = {'alfa': ascii_letters,
            'num':digits,
            'anum': ascii_letters + digits,
            'all': ascii_letters + digits + punctuation}

    ch_set = chars[char_set] + additional

    choice = SystemRandom().choice

    passwd = "".join(choice(ch_set) for _ in range(length))

    click.echo(passwd)

if __name__ == '__main__':
    gen_pass()
It generates eight symbols length alfanumerical password as default.
The first parameter is the length as an integer.
The second is between alfa: lower-upper ascii letters, num: digits, anum: ascii_letters + digits, all: letters + digits + puncutuation
The third one is quoted string of aditional characters

I did not separate lower and upper case letters and ther is no help.
Pages: 1 2