2017-11-30 13 views
0

ここでこんにちは、私のコードはランダムなパスワードジェネレータです。入力の検証 - Python

import string 
import random 
wt = input('Strength of the password: ') 
while wt in (1,2,3): 
    if wt == 1: 
     pword = random.choice(['helloworld','environment','superman','textbook','sandwich','light','sparrow']) 

    elif wt == 2: 
     pword = ''.join(random.choice(string.ascii_lowercase + string.digits) for i in range(8)) 

    elif wt == 3: 
     pword = ''.join(random.choice(string.ascii_uppercase + string.ascii_lowercase + string.digits) for i in range(8)) 

    print pword 

    break 

私はきちんと重量の入力の検証に成功していない(ブロック除き、してみてください) 私は重量のための入力検証の実装を支援してください。

+0

[ 'あるmkpasswd(..)'](http://code.activestate.com/recipes/578468-password-generator-mkpasswd/) –

+0

私は思います'wt'はここでは複雑さを意味します。正規表現を使用して、パスワードに大文字小文字、大文字、特殊文字、および数字が含まれていることを確認することができます。また、パスワードの長さの最小要件を満たすためにlenを使用してチェックを追加します。 – Sharad

+0

* input *とは何ですか? – Nabin

答えて

0

intに入力を変換します -

import string 
import random 
wt = int(input('Strength of the password: ')) 
while wt in (1,2,3): 
    if wt == 1: 
     pword = random.choice(['helloworld','environment','superman','textbook','sandwich','light','sparrow']) 

    if wt == 2: 
     pword = ''.join(random.choice(string.ascii_lowercase + string.digits) for i in range(8)) 

    if wt == 3: 
     pword = ''.join(random.choice(string.ascii_uppercase + string.ascii_lowercase + string.digits) for i in range(8)) 

    print pword 

    break