密码强度测量库。
passwordmeter的Python项目详细描述
可配置、可扩展的密码强度度量库。
项目
tl;dr
安装:
$ pip install passwordmeter
在应用程序中使用,默认因子为:
importpasswordmeterstrength,improvements=passwordmeter.test(sys.argv[1])ifstrength<0.5:print'Your password is too weak.'
在命令行上使用:
$ pwm 'password' Password strength: 0.132549901057 (Extremely weak) Possible improvements: - Use a good mix of numbers, letters, and symbols - Avoid using one of the ten thousand most common passwords - Use a good mix of UPPER case and lower case letters
概述
密码表包提供的主要功能是 Meter.test()方法,返回(float,dict)的元组。这个 float是密码在0到1(包括0到1)范围内的强度, 其中0非常弱,1非常强。第二次 参数可以是None,它是密码的字典 可以改进。口述的要点是 改进固定字符串密码(例如“长度”)的方法, 这些值是对人类友好的国际化字符串。 描述并可能根据特定密码定制。
密码的强度是通过做一个加权的,倾斜的, 一组“因子”的曲线平均值。构造函数接受 设置配置、自定义和/或补充的字典 默认的因素集。
passwordmeter.test是一个助手函数,它只使用 测试密码强度的默认设置,以及 实际上是Meter().test(...)的速记。
例如,要使用自定义的因子选择:
importpasswordmeter# use only the 'length' and 'charmix' factorsmeter=passwordmeter.Meter(settings=dict(factors='length,charmix'))strength,improvements=meter.test('s3cr3t p4ssW0RD!')
设置
meter构造函数的设置属性是一个字典 使用以下键:
factors:
这是一个逗号分隔的因子列表,用于计算 密码的强度。列表中的每个元素都是 由asset module定义的已知因子或符号规范。见 passwordmeter.DEFAULT_FACTORS用于默认因子列表 (还有他们的名字)。
例如,仅使用“长度”因子和自定义因子:
importpasswordmeterclassSillyFactor(passwordmeter.Factor):category='silly'deftest(self,value,extra):ifvalue=='silly':return(0,'That is a silly password!')return(1,None)meter=passwordmeter.Meter(settings=dict(factors=['length',SillyFactor]))# or, same thing, but using an asset-spec:meter=passwordmeter.Meter(settings=dict(factors='length,mypackage.SillyFactor'))
factor.{NAME}.{ATTRIBUTE}:
在初始化期间设置因子的属性。如果 表单factor.{NAME}.class是为中未列出的因子指定的 因子设置,因子将自动添加到 因素。这是将自定义因子添加到 默认列表。
以下属性是“特殊的”(所有属性都是可选的):
Attribute Interpretation ^{tt7}$ Specifies the asset-spec for the factory that can generate a Factor of this type. ^{tt9}$ Specifies the relative weight of this factor (default: 1). ^{tt10}$ Adds the specified amount to factor score (default: 0). ^{tt11}$ Multiplies the factor score by the specified amount – similar to weight, but is applied before clipping (default: 1). ^{tt12}$ Force a minimum score for this factor (default: 0). ^{tt13}$ Force a maximum score for this factor (default: 1.3). ^{tt14}$ Override the default improvement category. INI文件中的以下示例设置将给出长度 因子附加权重以及添加“mypkg.myfactor” 自定义因子(用参数msg设置为初始化 'abort')发送到仪表列表:
factor.length.weight=2.5factor.cust.class=mypkg.MyFactorfactor.cust.msg=abort
pessimism:
密码强度引擎权重低分数高于高分数 分数。发动机权重低得分的程度由 设置默认为10–越高, 分数越低,平均分就越低。例如,使用 默认悲观情绪为10,两个分数分别为0.75和0.25 平均值为0.4(而不是0.5的真实平均值)。
threshold:
指定改进消息应该使用的最大分数 返回。如果没有指定,所有可能的改进将是 返回,即使相关因子返回完美分数(1.0 或更大)。
自定义因子
自定义因子应子类化passwordmeter.factor,实现 测试方法,并具有唯一的类别(字符串)属性。
测试方法采用两个参数:要测试的值,以及 调用提供的不透明的额外参数 应用程序(如果不需要可以忽略)。它应该返回一个 元组(float,str)。
返回元组的第一个元素(float)必须大于或等于 归零。阿尔州gh一般不应大于1.0,a factormay返回一个更大的值:这用于人工 提高整体结果相对于其他因素的强度 如果适用。但是,请注意,meter类将始终剪裁 包含范围[0,1]的最终结果。
返回元组的第二个元素应该是字符串,它是 说明如何改进提供的密码。这个字符串可以 如果没有已知的方法来改进此密码,则为{TT2}$ 具体因素。注意,meter类将与此描述关联 最终结果中包含因素的类别。