northox/stupid-password

此包已废弃,不再维护。未建议替代包。

提供一种简单的方法,防止用户使用容易被猜到/暴力破解的密码。

v2.0 2018-11-24 16:52 UTC

This package is not auto-updated.

Last update: 2020-10-02 20:51:22 UTC


README

StupidPass.class.php提供了一种简单的方法来防止用户使用容易被猜到/暴力破解的密码。它旨在废弃crack-lib PHP扩展

描述

StupidPass.class.php是一个PHP库,提供简单但相当有效的密码验证规则。

该库实现了1337 speaking extrapolation。这会将提供的密码转换为可能的简单修改的详尽列表,例如将字母a更改为@4,这是最终用户为了满足复杂性规则而广泛使用的。完整的修改列表如下。然后,该列表与基于对最新的密码数据库泄露(linkedin、stratfor、sony、phpbb、rockyou、myspace)的研究得到的常见密码进行比较。此外,它还验证了长度和多个字符集的使用(大写字母、小写字母、数字、特殊字符)——后者大大减少了常见密码列表的大小。

以下是要求

  • 确保长度至少为8个字符;并且
  • 确保包含4个字符集(即大写字母、小写字母、数字和特殊字符);并且
  • 如果提供了环境上下文,列表必须不与环境上下文(正则表达式)匹配(例如,公司的名称、应用的名称、网站的名称、用户名等);并且
  • 列表必须不与提供的基于通过分析最新的受损害密码数据库(stratfor、sony、phpbb、myspace等)获得的常见弱密码的字典匹配。

此外

  • 通过实现反暴力破解技术来减轻在线攻击;
  • 通过使用强哈希算法(如PBKDF2)来减轻离线攻击。

一些数学

stupid password提供的可能组合的最小可能组合是:小写字母 + 大写字母 + 数字 + 特殊字符 = (26 + 26 + 10 + 10)^8 = 72^8 = 7.222041363×10¹⁴

注意:我只考虑了特殊字符的10种可能性,因为大多数用户只使用键盘顶部的字符。

如果你考虑放宽要求,请务必注意,删除数字或特殊字符集(62^8 = 2.183401056×10¹⁴)比使用包含所有字符集的7个字符密码(72^7 = 1.0030613×10¹³)要好。

1337 speak转换表

@ => a, o  
4 => a
8 => b
3 => e
1 => i, l
! => i, l, 1
0 => o
$ => s, 5
5 => s
6 => b, d
7 => t

用法

最简单的用法如下

use StupidPass;
$simplePass = new StupidPass();
$bool = $simplePass->validate($PasswordToTest);

最复杂的用法场景可能如下

// Override the default errors messages
$hardlang = array(
  'length'      => 'Password must be between %s and %s characters inclusively',
  'upper'       => 'Password must contain at least one uppercase character',
  'lower'       => 'Password must contain at least one lowercase character',
  'numeric'     => 'Password must contain at least one numeric character',
  'special'     => 'Password must contain at least one special character',
  'common'      => 'Password is too common',
  'environ'     => 'Password uses identifiable information and is guessable',
  'onlyNumeric' => 'Password must not be entirely numeric'
);

// Supply reference of the environment (company, hostname, username, etc)
$environmental = array('northox', 'github', 'stupidpass', 'stupidpassword');

// Additional options
$options = array(
  'disable' => array('special'),
);

// The first parameter is the max length
use StupidPass;
$stupidPass = new StupidPass(40, $environmental, './StupidPass.default.dict', $hardlang, $options);
if($stupidPass->validate($PasswordToTest) === false) {
  print('Your password is weak:<br \>');
  foreach($stupidPass->getErrors() as $error) {
    print($error . '<br />');
  }
}

可能的选项

  • 'disable' (数组):禁用指定的测试,例如array('special', 'lower')来禁用特殊和大小写字符的测试。
  • 'maxlen-guessable-test' (整数): 禁用环境检查和常见密码检查,对于长度超过给定整数的密码(由于内存和CPU占用过高)。默认值:24。

请注意,最小长度要求为8是硬编码的,无法更改。

PHP 单元测试

$ ./vendor/bin/phpunit tests/Tests/StupidPassTest.php
PHPUnit 3.7.38 by Sebastian Bergmann.

.......................

Time: 43 ms, Memory: 4.00MB

OK (23 tests, 45 assertions)

许可证

BSD 许可证。换句话说,它是免费软件,几乎免费如免费啤酒。

源代码

https://github.com/northox/stupid-password

作者

Danny Fullerton - Mantor 组织

贡献者