Python Pass Checker - 密码有效后,不会显示Point系统。通过发电机 - 弱,中,强破碎

时间:2017-11-11 14:03:32

标签: python

import random
import time
import re
import sys
import string
import os
from random import *

def menu():
    print("Welcome To A Password Generator And Checker")
    while True:
        try:
            choice = int(input("""
1) Generate Password
2) Check Password
3) Quit
"""))

            if choice == 1:
                gp()
            elif choice == 2:
                points = 0
                print("""
- Requirments -

You Must Include:
~ Uppercase Letter
~ Lowercase Letter
~ Number
~ Symbol
""")
                time.sleep(1)
                print("""
Point System:
~1 Uppercase Letter = 5 Points
~1 Lowercase Letter = 5 Points
~1 From 0-9 = 5 Points
~1 Allocated Symbol = 5 Points
~If Has All Add 10 Points
    """)
                passwd = input("Enter Your Desired Password: ")
                passwdVal(passwd)
            elif choice == 3:
                os.system("cls")
                print("Goodbye")
                time.sleep(0.5)
                sys.exit()
        except ValueError:
                    os.system("cls")
                    print("Please select a legitimate option")

def passwdVal(passwd):
    while passwd:
        if (len(passwd)<8 or len(passwd)>24):
            print("Your Length Is Either Too Big Or Too Small")
            print("Try Again")

        if not re.search("[a-z]",passwd):
            break
        elif not re.search("[0-9]",passwd):
            break
        elif not re.search("[A-Z]",passwd):
            break
        elif not re.search("[!$%^&()_]",passwd):
            break
        else:
            print("Valid Password")
            return True
            break


        while points < 35:
            if passwd:
                if 8 <= len(passwd) < 24 :
                    print(len(passwd),"Points Added - Length")
                    points += (len(passwd))

                else:
                    print("Wrong length, it must be 8 to 24 characters")
                    continue

                if re.search("[a-z]", passwd):
                    print("5 Points Added - Lowercase Letter")
                    points += 5

                if re.search("[0-9]", passwd):
                    print("5 Points Added - Number")
                    points += 5

                if re.search("[A-Z]", passwd):
                    print("5 Points Added - Uppercase Letter")
                    points += 5

                if re.search("[!$%^&()_]", passwd):
                    print("5 Points Added - Symbols")
                    points += 5

                if points == 20:
                    points += 10

                print("You have {} points".format(points))
                break
            else:
                print("Not a Valid Password")


def gp():
    gppoints = 0
    print("""
Generating Password:""")
    generation = string.ascii_letters+string.punctuation+string.digits
    gp = ("").join(choice(generation) for x in range(randint(8,12)))
    time.sleep(1)
    print("I will now show you your new and improved password")
    time.sleep(0.5)
    print("Enjoy")
    time.sleep(0.5)
    print(gp)
    while gppoints < 35:
            if gp:
                if 8 <= len(gp) < 24 :
                    print(len(gp),"Points Added - Length")
                    gppoints += (len(gp))

                else:
                    print("Wrong length, it must be 8 to 24 characters")
                    continue

                if re.search("[a-z]", gp):
                    print("5 Points Added - Lowercase Letter")
                    gppoints += 5

                if re.search("[0-9]", gp):
                    print("5 Points Added - Number")
                    gppoints += 5

                if re.search("[A-Z]", gp):
                    print("5 Points Added - Uppercase Letter")
                    gppoints += 5

                if re.search("[!$%&'()*+,-./:;<=>?@[\]^_`{|}~]", gp):
                    print("5 Points Added - Symbols")
                    gppoints += 5

                if gppoints == 20:
                    print("10 Points Added - All Of The Characters")
                    gppoints += 10

                print("You have {} points".format(gppoints))
                weakpass = gppoints  <15 
                mediumpass = gppoints  <25 
                strongpass = gppoints <35 
                excellentpass = gppoints <45
                if gppoints == weakpass:
                    print("Your Password Strength Is Weak")
                if gppoints == mediumpass:
                    print("Your Password Strenght Is Medium")
                if gppoints == strongpass:
                    print("Your Password Strength Is Strong")
                if gppoints == excellentpass:
                    print("Your Password Strength Is Excellent")
                break

            else:
                print("Not a Valid Password")




menu()

因此,对于密码生成器,我试图使密码有效(包含所有分配的字符),它显示关于密码的点系统。密码生成器工作,但我试图添加点系统。当我试图显示它是弱,中,强的密码时,分配的点可以工作。我尝试了很多东西,没有一个有效,所以我得到了帮助。非常感谢。

0 个答案:

没有答案