Python: password generator

Password generator for myself(works in python3).

# -*- coding:utf-8 -*-
from string import ascii_lowercase, ascii_uppercase, digits
import random


def iter_password(length=8, num_of_numbers=2, num_of_uppers=2):
    numbers = list(digits)
    uppers = list(ascii_uppercase)
    lowers = list(ascii_lowercase)
    num_of_lowers = length - num_of_numbers - num_of_uppers
    while True:
        random.shuffle(numbers)
        random.shuffle(uppers)
        random.shuffle(lowers)
        p = numbers[:num_of_numbers] + \
            uppers[:num_of_uppers] + \
            lowers[:num_of_lowers]
        random.shuffle(p)
        yield ''.join(p)

p = iter_password(length=6, num_of_numbers=1, num_of_uppers=1)
print(next(p))
# wSqvb7
print(next(p))
# caw4nR
print(next(p))
# i0Bpwu

 

Leave a Reply

Your email address will not be published. Required fields are marked *