nickjbedford/randomstringgenerator 问题修复 & 功能扩展

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

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

nickjbedford/randomstringgenerator

最新稳定版本:0.3.5

Composer 安装命令:

composer require nickjbedford/randomstringgenerator

包简介

Provides methods to generate cryptographically strong random strings based on an input alphabet.

README 文档

README

Generator\RandomStringGenerator generates cryptographically strong random strings based on a supplied alphabet of characters (such as alphanumeric characters). This is perfect for generating API keys within a set of allowed characters. It can also be used to generate strong passwords.

The class relies on the openssl_pseudo_random_bytes() function to generate the cryptographically strong random numbers for use in building the random strings.

Usage

To generate a 16-character string using the default 62-character alphanumeric alphabet, the usage is as simple as the following:

	$generator = new Generators\RandomStringGenerator();
	$key = $generator->generate();
	// string(16) "7m98Jvc0ArBDS4jK"

To use a different alphabet, such as uppercase hexadecimal characters, and to generate a random string of a different length, these parameters can be passed to the class as follows:

$generator = new RandomStringGenerator(RandomStringGenerator::ALPHABET_HEX_UPPER);
$key = $generator->generate(8);
// string(8) "CF70D24E"

A custom alphabet can be provided in the form of an input string of characters, such as:

$generator = new RandomStringGenerator('abc123');
$key = $generator->generate();
// string(16) "cb2c2a33c2c3a23b"

This is then converted to an array of characters internally. This array can be retrieved using the $generator->alphabet() function with no argument.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-01-31