定制 saacsos/randomgenerator 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

saacsos/randomgenerator

最新稳定版本:v1.1.0

Composer 安装命令:

composer require saacsos/randomgenerator

包简介

Generate Random String by level and length

README 文档

README

Laravel 5 Custom String Random Generator

Installation

$ composer require saacsos/randomgenerator

Basic Usage

<?php
use Saacsos\Randomgenerator\Util\RandomGenerator;

// Create an object
$randomGenerator = new RandomGenerator();

// Get random password
$randomGenerator->password();
$password = $randomGenerator->get();
// or
$password = $randomGenerator->password()->get();

// Get random access token (48 chars)
$accessToken = $randomGenerator->accessToken()->get();

Level & Length

Level of strength

  • 1 = number ([0-9])
  • 2 = hexadecimal ([0-9a-f])
  • 4 = lowercase (a-z except i,l,o)
  • 8 = uppercase (A-Z except I,L,O)
  • 16 = special character !@#$%^&*()_=[]{}?, Combine level for complex password
  • 5 = 1 + 4 = number + lowercase
  • 13 = 1 + 4 + 8 = number + lowercase + uppercase
  • 29 = 1 + 4 + 8 + 16 = number + lowercase + uppercase + special character
<?php

// get password 8 characters in level 5 
$password = $randomGenerator->level(5)->length(8)->password()->get();

Default level = 13, Default length = 8

isMatch($string, $strict=false)

Validate if $string match the level or not Strict mode will check $string must has at least 1 character in its level

<?php

$match = $randomGenerator->min(8)->max(8)->level(13)->isMatch('password'); // true
$match = $randomGenerator->min(8)->max(8)->level(13)->isMatch('password', true); // false because no uppercase

Laravel 5 Service Provider and Facades

Add your new provider to the providers array of config/app.php:

    'providers' => [
        // ...
        Saacsos\Randomgenerator\ServiceProvider\RandomGeneratorServiceProvider::class,
        // ...
    ],

Add class alias to the aliases array of config/app.php:

    'aliases' => [
        // ...
        'RandomGenerator' => Saacsos\Randomgenerator\Facades\RandomGenerator::class,
        // ...
    ],

And you can use

    $password = \RandomGenerator::password()->get();

统计信息

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

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

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