Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to judge the strength of a password by using regular expressions

2025-01-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

How to determine the strength of a password by using regular expressions? Many novices are not very clear about this. In order to help you solve this problem, the following editor will explain it in detail. People with this need can come and learn. I hope you can gain something.

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

Weak passwords: all numbers, symbols, letters

Medium password: numbers plus symbols, numbers plus letters, letters plus symbols

Strong password: three mixtures.

I am not case-sensitive, so I hope those who are interested can write it themselves. the problem occurs on\ w because\ w is equivalent to [A-Za-z0-9], so the string containing the descending line cannot be matched by\ W in the early stage.

Let's take a look at the medium password, number plus symbol or letter or _ is a group, letter plus symbol or underscore or symbol is a group, symbol or underscore plus letter or number is a group. I always think that the code in this does not seem to be right, but there is nothing wrong through the test, so let's use this version 0.0.1 first.

Test code

If _ _ name__ = ='_ main__': passwords = ('11a), LLZ, 1aL, 1a, 1a, 1a, 1a.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report