Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

PHP library for simple, secure random string generation (e.g. - passwords / salts).

License

NotificationsYou must be signed in to change notification settings

PHLAK/StrGen

Repository files navigation

StrGen

Join the CommunityBecome a SponsorOne-time Donation
Latest Stable VersionTotal DownloadsLicense

PHP library for simple secure random string generation (e.g. - passwords / salts)
Created byChris Kankiewicz (@PHLAK)


Requirements

Install with Composer

composer require phlak/strgen

Usage

// Import StrGenusePHLAK\StrGen;// Initialize the Generator$generator =newStrGen\Generator();// Generate a random string of characters$generator->length(16)->generate();// Returns something like '8a*Ag@I0*s0v[S3u'

Character Sets

StrGen has a few built-in character sets available for ease of use. You canspecify which set(s) to use by passing a character set or an array of sets tothecharset() method.

Example using built-in sets:

$generator =newStrGen\Generator();$generator->charset(StrGen\CharSet::ALPHA_NUMERIC)->generate();// or$generator->charset([StrGen\CharSet::MIXED_ALPHA,StrGen\CharSet::NUMERIC])->generate();

Available presets:

KeyCharacter Set
StrGen\CharSet::LOWER_ALPHAabcdefghijklmnopqrstuvwxyz
StrGen\CharSet::UPPER_ALPHAABCDEFGHIJKLMNOPQRSTUVWXYZ
StrGen\CharSet::MIXED_ALPHAabcdefghijklmnopqrstuvwxyz
ABCDEFGHIJKLMNOPQRSTUVWXYZ
StrGen\CharSet::NUMERIC0123456789
StrGen\CharSet::ALPHA_NUMERICabcdefghijklmnopqrstuvwxyz
ABCDEFGHIJKLMNOPQRSTUVWXYZ
0123456789
StrGen\CharSet::SPECIAL!@#$%^&*()-_=+.?{}[]<>:;/\|~
StrGen\CharSet::ALLabcdefghijklmnopqrstuvwxyz
ABCDEFGHIJKLMNOPQRSTUVWXYZ
0123456789
!@#$%^&*()-_=+.?{}[]<>:;/\|~

Custom sets:

You can also manually define a character set by passing a string of charactersto thecharset() method.

$generator =newStrGen\Generator();$generator->charset('0123456789abcdef')->generate();

Convenience Functions

StrGen also has built-in convenience functions for generating strings from theincluded character sets or a custom character set.

$generator->lowerAlpha($length);$generator->upperAlpha($length);$generator->mixedAlpha($length);$generator->numeric($length);$generator->alphaNumeric($length);$generator->special($length);$generator->all($length);$generator->custom($length,$charset);

Changelog

A list of changes can be found on theGitHub Releases page.

Troubleshooting

For general help and support join ourSpectrum community.

Please report bugs to theGitHub Issue Tracker.

Copyright

This project is licensed under theMIT License.

About

PHP library for simple, secure random string generation (e.g. - passwords / salts).

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp