输入正确的密码长度会重新启动我的程序?

时间:2014-10-16 16:31:34

标签: python

我一直在创建一个程序,我想让它检查密码是弱,中等还是强。我已经定义了大写,小写和数字中的每一个,因此程序可以检查传递的强度。我设置它所以+ b + c(所有标志)都很强等等但是当我输入7个字符时,全部小写它只是重新启动我的程序。我需要它告诉我密码是弱的等等。如果有人能给我任何提示,我将不胜感激!谢谢!

import sys
import os
def checkPass():
    passLoop = True
    while passLoop:
        print("Welcome user!")
        x = len(input("Please enter your password, between 6 and 12 characters. "))#Asks for age
        if x <= 6 or x >= 12:
            print("Your password is the wrong length.")
            r = input("Please press any key to restart the program")
    passLoop = False
checkPass()
###########################
def upperCase(x):
    for char in x:
        if char.isupper():
            return(1)
        return(0)
###########################
def lowerCase(x):
    for char in x:
        if char.islower():
            return(1)
        return(0)
###########################
def digitFlag(x):
    for char in x:
        if char.isalnum():
            return(1)
        return(0)
###########################
def passStrength():
    a = upperCase
    b = lowerCase
    c = digitFlag
    totalValue =  a + b + c
    if totalValue == a or b or c:
        print("Your password is weak, please re-enter it!")
    if totalValue == a and b or a and c or b and c:
        print("Your password is medium, please re-enter it!")
    if totalValue == a and b and c:
        print("Your password is strong, please re-enter it!")
passStrength()

2 个答案:

答案 0 :(得分:0)

您没有提及您的描述中引发的任何堆栈跟踪或异常,但我认为这就是您正在发生的事情。问题是你使用input()。将其更改为raw_input(),您应该开始获得您期望的功能。

你听说过iPython吗?它只是一个python shell环境,但它可能是一个实用程序,可以帮助您更清楚地看到发生了什么(注意甚至事后调试您的应用程序)。

如果这不能为您解决问题,请告诉我。

答案 1 :(得分:0)

你的问题是passLoop = False永远不会到达

试试这个:

def checkPass():
    passLoop = True
    while passLoop:
        print("Welcome user!")
        x = len(input("Please enter your password, between 6 and 12 characters. "))#Asks for age
        if x <= 6 or x >= 12:
            print("Your password is the wrong length.")
            r = input("Please press any key to restart the program")
        else:
            passLoop = False