判断最少6位密码密码强度,数字、小写字母、大写字母和指定的标点符号,分别对应 weak、 below middle 、above middle 、strong。
时间: 2024-02-01 10:02:43 浏览: 34
好的,我可以帮你写一个判断密码强度的Python程序:
```python
import re
def check_password_strength(password):
# 判断密码长度是否大于等于6
if len(password) < 6:
return "weak"
# 判断密码是否包含数字、小写字母、大写字母和指定的标点符号
has_digit = bool(re.search(r'\d', password))
has_lower = bool(re.search(r'[a-z]', password))
has_upper = bool(re.search(r'[A-Z]', password))
has_symbol = bool(re.search(r'[@$!%*#?&]', password))
# 根据包含的字符类型数量判断密码强度
count = has_digit + has_lower + has_upper + has_symbol
if count == 1:
return "weak"
elif count == 2:
return "below middle"
elif count == 3:
return "above middle"
else:
return "strong"
```
你可以调用这个函数并传入密码作为参数,它会返回对应的密码强度。例如:
```python
password = "abc123"
strength = check_password_strength(password)
print(strength) # 输出 "below middle"
```
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![txt](https://img-home.csdnimg.cn/images/20210720083642.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)