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


Messages In This Thread
mkpw: rewriting in python 3 - by Skaperen - Mar-10-2017, 05:33 AM
RE: mkpw: rewriting in python 3 - by varung1985 - Mar-16-2017, 10:07 AM
RE: mkpw: rewriting in python 3 - by Skaperen - Mar-17-2017, 05:49 AM
RE: mkpw: rewriting in python 3 - by Ofnuts - Mar-16-2017, 01:01 PM
RE: mkpw: rewriting in python 3 - by wavic - Mar-17-2017, 08:13 AM
RE: mkpw: rewriting in python 3 - by Larz60+ - Mar-17-2017, 01:37 PM
RE: mkpw: rewriting in python 3 - by Skaperen - Mar-18-2017, 02:23 AM
RE: mkpw: rewriting in python 3 - by nilamo - Mar-17-2017, 06:55 PM
RE: mkpw: rewriting in python 3 - by snippsat - Mar-17-2017, 07:38 PM
RE: mkpw: rewriting in python 3 - by nilamo - Mar-17-2017, 07:42 PM
RE: mkpw: rewriting in python 3 - by wavic - Mar-18-2017, 11:28 AM

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