Code Monkey home page Code Monkey logo

strgen's Introduction

StrGen

Join the Community Become a Sponsor One-time Donation
Latest Stable Version Total Downloads License

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


Requirements

Install with Composer

composer require phlak/strgen

Usage

// Import StrGen
use PHLAK\StrGen;

// Initialize the Generator
$generator = new StrGen\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 can specify which set(s) to use by passing a character set or an array of sets to the charset() method.

Example using built-in sets:

$generator = new StrGen\Generator();

$generator->charset(StrGen\CharSet::ALPHA_NUMERIC)->generate();

// or

$generator->charset([StrGen\CharSet::MIXED_ALPHA, StrGen\CharSet::NUMERIC])->generate();

Available presets:

Key Character Set
StrGen\CharSet::LOWER_ALPHA abcdefghijklmnopqrstuvwxyz
StrGen\CharSet::UPPER_ALPHA ABCDEFGHIJKLMNOPQRSTUVWXYZ
StrGen\CharSet::MIXED_ALPHA abcdefghijklmnopqrstuvwxyz
ABCDEFGHIJKLMNOPQRSTUVWXYZ
StrGen\CharSet::NUMERIC 0123456789
StrGen\CharSet::ALPHA_NUMERIC abcdefghijklmnopqrstuvwxyz
ABCDEFGHIJKLMNOPQRSTUVWXYZ
0123456789
StrGen\CharSet::SPECIAL !@#$%^&*()-_=+.?{}[]<>:;/\|~
StrGen\CharSet::ALL abcdefghijklmnopqrstuvwxyz
ABCDEFGHIJKLMNOPQRSTUVWXYZ
0123456789
!@#$%^&*()-_=+.?{}[]<>:;/\|~

Custom sets:

You can also manually define a character set by passing a string of characters to the charset() method.

$generator = new StrGen\Generator();

$generator->charset('0123456789abcdef')->generate();

Convenience Functions

StrGen also has built-in convenience functions for generating strings from the included 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 the GitHub Releases page.

Troubleshooting

For general help and support join our Spectrum community.

Please report bugs to the GitHub Issue Tracker.

Copyright

This project is licensed under the MIT License.

strgen's People

Contributors

alfredbez avatar dependabot-preview[bot] avatar peter279k avatar phlak avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

strgen's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.