def gen_passwd(pwd_len=min_allowed_pwd_len, strict_policy=0, seed=None):
    """
    Generates Paswords of pwd_len, that optinally strictly follows
    the Password Policy.

    if pwd_len < min_possible_len then policy cannot be enforced - if this happens,
    and strict_policy=1 it returns None.

    If pwd_len = min_possible_pwd_len then generate 4 unique tokens from vc, 1 token from
    vn and 1 token from vsc.

    if pwd_len > min_possible_pwd_len, then do as in previous step and then randomize the rest of the tokens.
    """

    # Basic and obvious input checking
    if strict_policy:
        if pwd_len < min_allowed_pwd_len:
            return None

    # Since we are generating passwords, we are nice to the poor
    # sods having to read and type them in, so we remove some
    # typcial character ambiguities. Yes, I know, this reduces the
    # Password Variation Space. See if I care - you're not the one
    # having to read the passwords or deal with complaints about that :-)
    # So, we reduce special chars
    rvs = vsc.replace(' ', '') # remove space
    rvs = rvs.replace('|', '') # remove pipe
    # reduce valid numbers
    rvn =  vn.replace('1', '') # remove nr 1
    rvn = rvn.replace('0', '') # remove zero
    # reduce valid chars
    rvc =  vc.replace('l', '') # remove lowercase L
    rvc = rvc.replace('I', '') # remove uppercase I
    rvc = rvc.replace('O', '') # remove uppercase O

    from random import Random
    if seed is None:
        seed = time() * time()
    gen = Random(seed)

    if not strict_policy:
        pl = gen.sample(rvc + rvn + rvs, pwd_len)
        return ''.join(pl)

    # We have a strict enforcement policy. Try for ten iterations, if not 
    # successfull then return None.
    rl_len = pwd_len - (min_char_tokens + min_num_tokens + min_special_tokens)
    for i in range(1,10):
        pl = gen.sample(rvc, min_char_tokens)    + \
             gen.sample(rvn, min_num_tokens)     + \
             gen.sample(rvs, min_special_tokens) + \
             gen.sample(rvc + rvn + rvs, rl_len)
        gen.shuffle(pl)
        pwd = ''.join(pl)
        err = check_passwd(pwd)
        if err == []:
            return pwd
    return None

    Generates Paswords of pwd_len, that optinally strictly follows
    the Password Policy.

    if pwd_len < min_possible_len then policy cannot be enforced - if this happens,
    and strict_policy=1 it returns None.

    If pwd_len = min_possible_pwd_len then generate 4 unique tokens from vc, 1 token from
    vn and 1 token from vsc.

    if pwd_len > min_possible_pwd_len, then do as in previous step and then randomize the rest of the tokens.
    
recipes/Python/576561_Configurable_password/recipe-576561.py