【问题标题】:Problems with Python password checkerPython密码检查器的问题
【发布时间】:2017-01-08 05:51:27
【问题描述】:

我在 Python 中创建了一个密码检查器。这是我使用的代码:

import easygui as eg

def pword():
    global password
    global lower
    global upper
    global integer
    password = eg.enterbox(msg="Please enter your password")
    length = len(password)
    print(length)
    lower = sum([int(c.islower()) for c in password])
    print(length)
    upper = sum([int(c.isupper()) for c in password])
    print (upper)
    integer = sum([int(c.isdigit()) for c in password])
    print (integer)

def length():
    global password
    if len(password) < 6:
        eg.msgbox(msg="Your password is too short, please try again")
    elif len(password) > 12:
        eg.msgbox(msg="Your password is too long, please try again")

def strength():
    global lower
    global upper
    global integer
    if (lower) < 1:
        eg.msgbox(msg="Please use a mixed case password with lower case    letters")
    elif (upper) < 1:
        eg.msgbox(msg="Please use a mixed case password with UPPER clase letters")
    elif (integer) < 1:
        eg.msgbox(msg="Please try adding a number")
    else:
        eg.msgbox(msg="Strength Assessed - Your password is ok")

while True:
    pword()
    length()
    strength()

answer = eg.choicebox(title="Try again?",msg="Would you like to try again?", choices=("Yes","No"))
if answer !="Yes":
    sys.exit()

当我运行该模块时,它只会出现以下消息:

重启:C:\Users\PGUSER72\AppData\Local\Programs\Python\Python35-32\python 密码 8.py

当我重新启动时,它只会显示 RESTART - Shell

【问题讨论】:

  • 你能修正你的缩进吗?
  • 首先,清理你的缩进,然后修复全局变量的不必要和不安全的使用

标签: python string function file passwords


【解决方案1】:

我修正了你的缩进

您的代码有效,在 Ubuntu 14.04 LTS 上测试

编辑:

还在 Windows 7 32bit python 2.7.12 上测试

一切正常。你是如何运行你的脚本的?

【讨论】:

  • 很确定 OP 使用的是 Windows。
  • 我刚刚在windows上添加了测试报告
猜你喜欢
  • 2016-12-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-02-09
  • 1970-01-01
  • 1970-01-01
  • 2016-07-22
  • 2014-11-08
相关资源
最近更新 更多