Python string to judge the password strength

The examples in this article share the specific code for judging Python password strength for your reference. The specific content is as follows

Program description: By obtaining user input, determine whether the password length is greater than 8, and at the same time determine whether it contains numbers and letters, and return relevant information.

【Related knowledge points】

**Python string: **

str.isnumeric() --- Check whether the string has only numbers and return True or False (note that there are only numbers)
str.isalpha() --- Check whether there are only letters in the string and return True or False
str.islower() --- Check whether the string is all lowercase
str.isupper() ——Check whether the string is all uppercase

"""
 Author: Wang Xiao North
 Date: 2019.05.19
 Function: Determine the strength of the input password
 Version: v2.0
 Added function: Cycle termination
"""

# Determine whether the input string contains numbers
def existNumber(password_str):
 has_number = False
 for c in password_str:if c.isnumeric():
 has_number = True
 breakreturn has_number
 # Generally, two returns are not used consecutively in the program
 # return True #return terminates the loop early
 # return False

# Determine whether the input string contains letters
# def existAlpha(password_str):
# for c in password_str:
# if c.isalpha():
# return True
# return False

# v2.0 Determine whether the input string contains letters
def existAlpha(password_str):
 has_Alpha = False
 for c in password_str:if c.isalpha():
 has_Alpha = True
 breakreturn has_Alpha

def main():"""
 Main function
 : return:12"""

 Try_times =5while Try_times   0:
 password =input('Please enter your password:')
 # password strength
 strength_level =0

 # Rule 1: The password length is greater than 8iflen(password)=8:
 strength_level +=1else:print('Please enter a password longer than 8...')

 # Rule 2: Determine whether there are numbers
 ifexistNumber(password):
 strength_level +=1else:print('Password must contain numbers')

 # Rule 3: The password contains letters
 ifexistAlpha(password):
 strength_level +=1else:print('Password must contain letters')if strength_level ==3:print('The password is entered correctly!')breakelse:
 Try_times -=1if Try_times ==0:print('Too many incorrect passwords!')else:print('wrong password! Remaining{}Times'.format(Try_times))print() #Add blank line

if __name__ =='__main__':main()

The above is the whole content of this article, I hope it will be helpful to everyone's study.

Recommended Posts

Python string to judge the password strength
The best way to judge the type in Python
Python implements password strength verification
How to save the python program
The premise of Python string pooling
How to view the python module
Python string
Python string
Python novice learns to use the library
How to learn the Python time module
How to use the round function in python
Python string manipulation
How to use the zip function in Python
Python uses the email module to send mail
An article to understand the yield in Python
01. Introduction to Python
How to use the format function in python
How to enter python through the command line
2.1 The Python Interpreter (python interpreter)
How to switch the hosts file using python
How to install the downloaded module in python
Python how to move the code collectively right
Introduction to Python
Use python to realize the aircraft war game
Python reads the result and writes it to Excel
What are the methods for python to connect to mysql
How to understand the introduction of packages in Python
Using Python to analyze the Guangzhou real estate market
How does python judge the module installation is complete
The specific steps to upgrade python on Raspberry Pi
Python simulation to realize the distribution of playing cards
What are the ways to open files in python
Python uses the re module to verify dangerous characters
Centos 6.4 python 2.6 upgrade to 2.7
Centos 6.4 python 2.6 upgrade to 2.7
Consolidate the Python foundation (2)
Str string in Python
Python | An article to understand Python list, tuple and string operations
Minimalism is the soul of Python | Python code to find bugs (10)