


Share an example of using regular expressions to determine the strength of a password
This article will share with you an example code that uses regular expression to determine the strength of a password. It is very good and has reference value. Friends who need it can refer to it
learn python's re template, I wrote an article and found that no one read it, so I summarized my experience. No one loves theory, but people's hearts are in practice. So since no one likes theory, just go to practice and refine the theory in practice. Without further ado, let’s just start with the code
def password_level(password): weak = re.compile(r'^((\d+)|([A-Za-z]+)|(\W+))$') level_weak = weak.match(password) level_middle = re.match(r'([0-9]+(\W+|\_+|[A-Za-z]+))+|([A-Za-z]+(\W+|\_+|\d+))+|((\W+|\_+)+(\d+|\w+))+',password) level_strong = re.match(r'(\w+|\W+)+',password) if level_weak: print 'password level is weak',level_weak.group() else: if (level_middle and len(level_middle.group())==len(password)): print 'password level is middle',level_middle.group() else: if level_strong and len(level_strong.group())==len(password): print 'password level is strong',level_strong.group()
Explain it
Weak password: all numbers, symbols, letters
Medium password: Numbers plus symbols, numbers plus letters, letters plus symbols
Strong password: Mix of three.
I am not case sensitive, I hope those who are interested can write it themselves. The problem occurs with \w because \w is equivalent to [A-Za-z0-9_], so the string containing the underline cannot be matched through \W in the early stage
Let’s take a look Look at the medium password. Numbers plus symbols or letters or _ are a group. Letters plus symbols or underlines or symbols are a group. Symbols or underscores plus letters or numbers are a group. I always feel that the code in this seems wrong, but After passing the test and finding nothing wrong, just use this version 0.0.1 first
Test code
if name == 'main': passwords = ('11','aa','LL','1a','1_','a_','a1','_1','*a','1a_','1a<') for pw in passwords: password_level(pw) '''----------------------output------------------------ #password level is weak 11 #password level is weak aa #password level is weak LL #password level is middle 1a #password level is middle 1_ #password level is middle a_ #password level is middle a1 #password level is middle _1 #password level is middle *a #password level is strong 1a_ #password level is strong 1a< '''
The above is the detailed content of Share an example of using regular expressions to determine the strength of a password. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Quark Netdisk and Baidu Netdisk are very convenient storage tools. Many users are asking whether these two softwares are interoperable? How to share Quark Netdisk to Baidu Netdisk? Let this site introduce to users in detail how to save Quark network disk files to Baidu network disk. How to save files from Quark Network Disk to Baidu Network Disk Method 1. If you want to know how to transfer files from Quark Network Disk to Baidu Network Disk, first download the files that need to be saved on Quark Network Disk, and then open the Baidu Network Disk client. , select the folder where the compressed file is to be saved, and double-click to open the folder. 2. After opening the folder, click "Upload" in the upper left corner of the window. 3. Find the compressed file that needs to be uploaded on your computer and click to select it.

1. First, we enter NetEase Cloud Music, and then click on the software homepage interface to enter the song playback interface. 2. Then in the song playback interface, find the sharing function button in the upper right corner, as shown in the red box in the figure below, click to select the sharing channel; in the sharing channel, click the "Share to" option at the bottom, and then select the first "WeChat Moments" allows you to share content to WeChat Moments.

PHP email detection: Determine whether the email has been sent successfully. When developing web applications, you often need to send emails to communicate with users. Whether it is registration confirmation, password reset, or sending notifications, the email function is an indispensable part. However, sometimes we cannot ensure whether the email is actually sent successfully, so we need to perform email detection and determine whether the email has been sent successfully. This article will introduce how to use PHP to implement this function. 1. Use SMTP server to send emails. First, we need to use SM

Recently, Baidu Netdisk Android client has ushered in a new version 8.0.0. This version not only brings many changes, but also adds many practical functions. Among them, the most eye-catching is the enhancement of the folder sharing function. Now, users can easily invite friends to join and share important files in work and life, achieving more convenient collaboration and sharing. So how do you share the files you need to share with your friends? Below, the editor of this site will give you a detailed introduction. I hope it can help you! 1) Open Baidu Cloud APP, first click to select the relevant folder on the homepage, and then click the [...] icon in the upper right corner of the interface; (as shown below) 2) Then click [+] in the "Shared Members" column 】, and finally check all

Mango TV has various types of movies, TV series, variety shows and other resources, and users can freely choose to watch them. Mango TV members can not only watch all VIP dramas, but also set the highest definition picture quality to help users watch dramas happily. Below, the editor will bring you some free Mango TV membership accounts for users to use, hurry up and take a look Take a look. Mango TV latest member account free sharing 2023: Note: These are the latest member accounts collected, you can log in directly and use them, do not change the password at will. Account number: 13842025699 Password: qds373 Account number: 15804882888 Password: evr6982 Account number: 13330925667 Password: jgqae Account number: 1703

Golang regular expressions use the pipe character | to match multiple words or strings, separating each option as a logical OR expression. For example: matches "fox" or "dog": fox|dog matches "quick", "brown" or "lazy": (quick|brown|lazy) matches "Go", "Python" or "Java": Go|Python |Java matches words or 4-digit zip codes: ([a-zA

HP printers are essential printing equipment in many offices. Installing the printer driver on the computer can perfectly solve problems such as the printer being unable to connect. So how to install HP printer driver? The editor below will introduce you to two HP printer driver installation methods. The first method: download the driver from the official website 1. Search the HP China official website in the search engine, and in the support column, select [Software and Drivers]. 2. Select the [Printer] category, enter your printer model in the search box, and click [Submit] to find your printer driver. 3. Select the corresponding printer according to your computer system. For win10, select the driver for win10 system. 4. After downloading successfully, find it in the folder

WPS is a popular office software that can greatly improve work efficiency whether in study, work or life. We often share wps files with friends who need them. How to do it specifically? Below, the editor will demonstrate the detailed operation. 1. Open the file that needs to be shared. 2. Click File, then click Share Document. 3. For permissions, select only designated people to view/edit, and then click Create and Share. 4. Then click Copy Link. 5. Open the way you want to share, such as sharing with WeChat friends, right-click the mouse in the input box and select paste. 6. Then click Send.
