npluis/passwordgenerator

1.0 2017-04-07 21:39 UTC

This package is not auto-updated.

Last update: 2024-09-29 01:22:48 UTC


README

Minimum PHP Version Build Status

PasswordGenerator

PHP 简易密码生成器

要求

  • PHP 7.0

安装

composer require npluis/passwordgenerator

使用密码生成器

基本用法

<?php
require 'vendor/autoload.php';


$generator = new \Npluis\PasswordGenerator\PasswordGenerator();
$password = $generator->create();
  • 长度在8到10之间: $generator->create(8,10);
  • 固定长度: $generator->create(12,12);
  • 仅包含a-zA-Z0-0: $generator->setAllowBrackets(false)->setAllowSpecial(false)->create();

高级用法

使用自定义字符集

$generator->setChars('AbCdEfG@#$%%<>;')->setAllowSpecial(false)->setAllowBrackets(false)

使用密码检查器

为了防止在创建新密码时生成或输入弱密码,您可以使用一些检查。

检查黑名单单词(如密码、管理员、qwerty等)

$checker->addToBlacklist('blacklist');
$checker->checkPassword('123blacklist'); //BLACKLIST_WORD
$checker->checkPassword('BlackList'); //BLACKLIST_WORD

检查弱密码,如1111或aaa,通过指定最小数量的唯一小写字母

$checker->setMinUniqueChars(3);
$checker->checkPassword('111Aa'); //UNIQUE_CHARS only two unique lowercase chars a and 1