Download the PHP package lamansky/random-password without Composer
On this page you can find all versions of the php package lamansky/random-password. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download lamansky/random-password
More information about lamansky/random-password
Files in lamansky/random-password
Package random-password
Short Description Uses cryptographically-secure randomization to generate a password of a given length from given sets of characters.
License MIT
Homepage https://github.com/lamansky/random-password
Informations about the package random-password
RandomPassword
A PHP library that uses cryptographically-secure randomization to generate a password of a given length from given sets of characters.
Installation
With Composer installed on your computer and initialized for your project, run this command in your project’s root directory:
Requires PHP 7.1 or above.
Examples
API
The library consists of a single class: Lamansky\RandomPassword\RandomPasswordFactory
.
Constructor Parameters
- Optional:
$set_codes
(string or null): A configuration string indicating the character sets that should be used in generating the random password. If this is set tonull
, the default ofu l n
(equivalent to the configuration of the staticalphanumeric()
method) will be used. - Optional:
$custom_set
(string): A set of characters to be used if$set_codes
includesc
.
Set Codes
The $set_codes
string is used to specify which characters should be used in generating random passwords. The available character sets are:
Code | Set Name | Set Characters |
---|---|---|
L |
Lowercase | abcdefghijklmnopqrstuvwxyz |
l |
Unambiguous Lowercase | abcdefhjkmnpqrstuvwxyz (Letters i, g, l, and o are omitted.) |
U |
Uppercase | ABCDEFGHIJKLMNOPQRSTUVWXYZ |
u |
Unambiguous Uppercase | ABCDEFHJKLMNPQRSTUVWXYZ (Letters I, G, and O are omitted.) |
N |
Numbers | 1234567890 |
n |
Unambiguous Numbers | 2345789 (Numbers 1, 6, and 0 are omitted.) |
s |
Symbols | !@#^*_ |
c |
Custom | Specified in the $custom_set variable. |
Passwords will be generated by rotating between different space-separated groups in your configuration string. Here are some sample values for $set_codes
with corresponding behavior:
Configuration String | Behavior | Sample Password |
---|---|---|
u l n |
The password will be generated by rotating between the u , l , and n sets (uppercase, lowercase, and numbers). The order of the rotation will be randomized. |
jR5nX8eH |
uln |
Every character of the password will have a chance of being drawn from the u , l , or n sets. |
29QVYbC7 |
ul n |
The password will be generated by rotating between letters (a mix of uppercase and lowercase) and numbers. | 9n5h4D8X |
Static Factory Methods
The RandomPasswordFactory
class has various static factory methods, each of which serves as a shortcut for constructing a factory using a preconfigured value for $set_codes
.
Static Method | Set Codes | Sample Password |
---|---|---|
alpha() |
u l |
sJtNbZtA |
numeric() |
N |
54088998 |
alphanumeric() |
u l n |
r9Tj4Nw5 |
loweralphanumeric() |
l n |
p7h2q4e2 |
ascii() |
u l n s |
7R_y5M#f |
custom($custom_set) |
c |
The generate()
Method
Parameters
$length
(int): The number of characters in the password to be generated. For security reasons, it is strongly recommended that this be set to12
or higher.- Optional:
$set_codes
(string or null): If set, overrides the global$set_codes
value set in the constructor. - Optional:
$custom_set
(string): If set, overrides the global$custom_set
value set in the constructor.
Return Value
Returns a random password as a string.
Unit Tests
To run the development test suite, execute this command: