Skip to content
This repository has been archived by the owner on Apr 4, 2024. It is now read-only.
/ password Public archive

πŸ”’ A simple library to generate passwords

License

Notifications You must be signed in to change notification settings

jarne/password

Repository files navigation

password

A simple library to generate passwords


Packagist version PHP version CircleCI License

β€’ Install
β€’ Usage
β€’ Examples
β€’ Contribution
β€’ License

πŸ“¦ Install

This library requires PHP 7.2 or newer in order to work correctly. You can install it with:

$ composer require jarne/password

If you don't like Composer, you can also clone the repository with:

$ git clone https://github.com/jarne/password

πŸ‘¨β€πŸ’» Usage

There are two functions in this library:

  • one to generate a random password
  • and one to generate a random one which is easy to remember because it sounds like a real word

The arguments are the same for both functions:

/**
 * Generate a password
 *
 * @param int $length
 * @param int $lettersChance
 * @param int $numbersChance
 * @param int $specialCharactersChance
 * @return string
 */
public function generate(
    int $length = 8,
    int $lettersChance = 1,
    int $numbersChance = 1,
    int $specialCharactersChance = 1
): string
/**
 * Generate an easy to remember password
 *
 * @param int $length
 * @param int $lettersChance
 * @param int $numbersChance
 * @param int $specialCharactersChance
 * @return string
 */
public function generateEasyToRemember(
    int $length = 8,
    int $lettersChance = 1,
    int $numbersChance = 1,
    int $specialCharactersChance = 1
): string

See the examples section for a short code example how to use it.

⌨️ Examples

Here are some examples how to use the functions.

Generate an 8-character long password:

$password = new Password();

$yourPassword = $password->generate();

echo "Your new password is " . $yourPassword;

If your password should only be 5 characters long, just change the second line to:

$yourPassword = $password->generate(5);

It's also possible to generate a password with more numbers than letters, for example:

$yourPassword = $password->generate(5, 1, 15, 1);

In the code above, the letter chance is set to 1, the numbers chance to 15, and the special characters chance to 1, so it's likely that the password contains more numbers than other characters.

πŸ™‹β€ Contribution

Contributions are always very welcome! It's completely equal if you're a beginner or a more experienced developer.

Please read our Contribution Guidelines before creating an issue or submitting a pull request.

Thanks for your interest πŸŽ‰πŸ‘!

πŸ‘¨β€βš–οΈ License

MIT

About

πŸ”’ A simple library to generate passwords

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages