什么是检查密码强度的最好方法? [英] What is the best way to check the strength of a password?
本文介绍了什么是检查密码强度的最好方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
什么是确保用户提供的密码是在注册或更改密码形式的强密码的最佳方法是什么?
编辑:我有一个想法(在python)
高清validate_password(passwd中):
conditions_met = 0
conditions_total = 3
如果len(passwd文件)> = 6:
如果passwd.lower()= passwd文件:conditions_met + = 1
如果len([X对于x在passwd文件,如果x.isdigit())> 0:conditions_met + = 1
如果len([X对于x在passwd中如果没有x.isalnum())> 0:conditions_met + = 1
结果=假
打印conditions_met
如果conditions_met> = 2:结果=真
返回结果
解决方案
根据不同的语言,我平时用普通的前pressions以检查是否有:
- 在至少一个大写字母和一个 小写字母
- 在至少一个数字
- 在至少一个特殊字符
- 的至少六个字符的长度
您可以要求上述所有的,或者使用脚本的强度仪型。对于我的实力计,如果密码有正确的长度,它是评价如下:
- 在一个条件满足:弱密码
- 在两个条件满足:中等密码
- 在所有条件都满足:强密码
您可以调整上述满足您的需求。
See also How do you compute password complexity?
What is the best way of ensuring that a user supplied password is a strong password in a registration or change password form?
EDIT: one idea I had (in python)
def validate_password(passwd):
conditions_met = 0
conditions_total = 3
if len(passwd) >= 6:
if passwd.lower() != passwd: conditions_met += 1
if len([x for x in passwd if x.isdigit()]) > 0: conditions_met += 1
if len([x for x in passwd if not x.isalnum()]) > 0: conditions_met += 1
result = False
print conditions_met
if conditions_met >= 2: result = True
return result
解决方案
Depending on the language, I usually use regular expressions to check if it has:
- At least one uppercase and one lowercase letter
- At least one number
- At least one special character
- A length of at least six characters
You can require all of the above, or use a strength meter type of script. For my strength meter, if the password has the right length, it is evaluated as follows:
- One condition met: weak password
- Two conditions met: medium password
- All conditions met: strong password
You can adjust the above to meet your needs.
这篇关于什么是检查密码强度的最好方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文