tseweb/php-pwpolicy 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

tseweb/php-pwpolicy

Composer 安装命令:

composer require tseweb/php-pwpolicy

包简介

Class to enforce a password policy.

关键字:

README 文档

README

A password policy enforcer.

Installation

composer require viavario/php-pwpolicy

Usage

<?php
$pwp = new TSEWEB\PasswordPolicy();

// Set the minimum password length
$pwp->minimumPasswordLength(10);

// Require at least 1 uppercase letter
$pwp->alphaUppercaseRequired(true);

// Require at least 1 lowercase letter
$pwp->alphaLowercaseRequired(true);

// Require at least 1 number
$pwp->numberRequired(true);

// Require at least 1 symbol
$pwp->symbolRequired(true);

// Require at least 1 number or symbol that is not
// the first or last character of the password
$pwp->midNumberOrSymbolRequired(true);

// Do not allow letters only
$pwp->disallowAlphasOnly(true);

// Do not allow numbers only
$pwp->disallowNumbersOnly(true);

// Do not allow consecutive lowercase letters
// E.g. 'foobar' is not allowed, but 'FoObAr' is
$pwp->disallowConsecutiveAlphaLC(true);

// Do not allow consecutive uppercase letters
// E.g. 'FOOBAR' is not allowed, but 'FoObAr' is
$pwp->disallowConsecutiveAlphaUC(true);

// Do not allow consecutive numbers
// E.g. 'example564' is not allowed, but '5ex6ample4' is 
$pwp->disallowConsecutiveNumbers(true);

// Do not allow repeated characters
// E.g. 'foobar' is not allowed, but 'fozbar' is
$pwp->disallowRepeatedChars(true);

// Do not allow sequential letters
// E.g. 'SampleAbC' is not allowed, but 'ASampleBC' is
// E.g. 'SampleCbA' is not allowed, but 'ASampleCB' is
$pwp->disallowSequentialAlphas(true);

// Do not allow sequential numbers
// E.g. 'Sample123' is not allowed, but '1Sample23' is
// E.g. 'Sample654' is not allowed, but '6Sample54' is
$pwp->disallowSequentialNumbers(true);

// Do not allow sequential symbols
// E.g. 'Sample&é"' is not allowed, but '&Sampleé"' is
$pwp->disallowSequentialSymbols(true);

// Require a minimum score
// The score is based on various variables, e.g. password length,
// the use of letters (uppercase and lowercase), numbers, symbols,
// if the password contains a common used password, if it may be a word
// and a number, the estimated time to brute force the password, ...
$pwp->minimumScore(100);

// Require a minimum complexity
// The complexity is based on the score of the password
// Valid complexities are:
//   TSEWEB\PasswordPolicy::COMPLEXITY_VERY_WEAK
//   TSEWEB\PasswordPolicy::COMPLEXITY_WEAK
//   TSEWEB\PasswordPolicy::COMPLEXITY_GOOD
//   TSEWEB\PasswordPolicy::COMPLEXITY_STRONG
//   TSEWEB\PasswordPolicy::COMPLEXITY_VERY_STRONG
$pwp->minimumComplexity(TSEWEB\PasswordPolicy::COMPLEXITY_VERY_STRONG);

// Require a minimum time to brute force the password
$pwp->minimumBruteForceTimeInSeconds(60*60*24*365*100);
// A well built computer can try up to 4*10^9 passwords per second.
// When using a slow hashing method you can change the keys per second to
// a low number, e.g. 100 per second.
$pwp->bruteForceKeysPerSecond(4000000000);

// Do not allow commonly used passwords (top 10000)
$pwp->disallowCommonPasswords(true);

// Validate a password against the set policy
$validOrFails = $pwp->validate('testing');
if ($validOrFails===true) {
	// Password meets the requirements of the password policy
}
else if (is_array($validOrFails)) {
	// Password does not meet the requirements of the password policy
	// $validOrFails is an array containing the requirements the password failed on
	// E.g. array(
	//   'common_password', // Password is a common password
	//   'minimum_length', // Password is shorter than minimum length
	//   'alpha_lc', // Password does not contain a lowercase letter
	//   'alpha_uc', // Password does not contain an uppercase letter
	//   'alphas_only', // Password consists of letters only
	//   'numbers_only', // Password consists of numbers only
	//   'consecutive_alpha_lc', // Password contains consecutive lowercase letters
	//   'consecutive_alpha_uc', // Password contains consecutive uppercase letters
	//   'consecutive_numbers', // Password contains consecutive numbers 
	//   'mid_number_or_symbol', // Password does not contain a number or symbol in the middle
	//   'number', // Password does not contain a number
	//   'symbol', // Password does not contain a symbol
    //   'repeat_chars', // Password contains duplicate characters
	//   'sequential_alpha', // Password contains 3 or more sequential letters
	//   'sequential_number', // Password contains 3 or more sequential numbers
	//   'sequential_symbol', // Password contains 3 or more sequential symbols
	//   'complexity', // Password does not have the required complexity
	//   'brute_force_time', // Password can be brute force cracked in a shorter time than required
	//   'minimum_score' // Password does not meet the minimum score
	// );
}

tseweb/php-pwpolicy 适用场景与选型建议

tseweb/php-pwpolicy 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 27k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2016 年 06 月 05 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「password policy」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 tseweb/php-pwpolicy 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 tseweb/php-pwpolicy 我们能提供哪些服务?
定制开发 / 二次开发

基于 tseweb/php-pwpolicy 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 27k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 5
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 3
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-06-05