mor / passgen
密码生成器
此包的规范存储库似乎已消失,因此该包已被冻结。
v0.9.3
2021-11-27 10:35 UTC
README
Mor/PassGen
Laravel 的密码生成器
使用 composer 安装包
composer require mor/passgen
使用此命令在项目中使用
use Mor\Passgen\Passgen;
生成
$length = 8 ; // default 8
$pass = Passgen::Generate($length, ['small', 'capital', 'number', 'special']);
密码生成器 ORM
$pass = new Passgen();
$pass->small(); // Use small letters
$pass = $pass->make($length); // Return generated password.
选项
$count = 4; // Minimum count of characters (default = 0 means random)
$exact = true; // Exact number of count
// if count = 4, exactly 4 charcters of this type will be found in the password. (default = false)
$pass->small($count, $exact);
$pass->capital(); // Use capital letters
$pass->number(); // Use number
$pass->special(); // Uuse special characters
$pass->contain('abc@7'); // Generated password should have these characters.
// Also you can pass an array
$pass->contain(['a','b','c', '@','7']);
$pass->notContain('sh4'); // Generated password should not have these characters. (also can pass an array)
字符串到密码
$string = 'something';
$type = 'before'; // Type of with: can be 'before' (add generated password before of string) or 'after' or 'both'
$pass->stringToPass($string)->with($length, $type, $useSmallLetters, $useCapitalLetters, $useNumbers, $useSpecialChars)->get();
额外
重新排序
$string = 'abcdefg';
$reOrder = Passgen::reOrder($string); // This will re-order the string: something like 'degfcab'.
高级
自定义字符
要添加自定义字符,创建一个类似这样的类
<?php
// Default folder of chars
namespace Mor\Passgen\Chars;
use Mor\Passgen\App\PasswordGenerator\Char;
class Custom extends Char {
// add custom characters as key
public $characters = [
'😀', '😁', '😛'
];
}
然后,在 Mor\Passgen\App\PasswordGenerator\Bootstrap.php 中注册您的自定义字符
...
use namespace Mor\Passgen\Chars\Custom;
...
...
public function __construct()
{
$this->registerChars([
...
Custom::class,
...
]);
}
...
要使用自定义字符,只需使用类名即可
$pass = new Passgen();
Passgen::Generate(8, ['custom']); // e.g: '😛😛😀😛😛😛😁😀' (return 32 characters because of emojies)
$pass->custom()->make(8); // e.g: '😀😀😛😀😁😀😀😁'
警告:在此示例中,我们使用了表情符号来创建密码,这 不推荐。
自定义字符名称
要为字符使用自定义名称,请将以下内容添加到您的自定义字符类中
public $name = 'CustomCharacter';
$pass = new Passgen();
Passgen::Generate(8, ['CustomCharacter']);
$pass->CustomCharacter()->make(8);