Python Forum
mkpw: rewriting in python 3
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
mkpw: rewriting in python 3
#11
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.
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Rewriting an applications in Python falsedmitri 4 2,850 Jun-03-2019, 01:42 PM
Last Post: heiner55

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020