Download the PHP package jabarihunt/password without Composer
On this page you can find all versions of the php package jabarihunt/password. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download jabarihunt/password
More information about jabarihunt/password
Files in jabarihunt/password
Package password
Short Description Simple Password class.
License MIT
Homepage https://github.com/jabarihunt/password
Informations about the package password
Password Class
This is a simple class that uses the standard PHP methods _password_hash() and password_verify()_ to create a hashed password and compare the hash to entered passwords respectively. The primary purpose of this class is to remove some of the boilerplate code required when performing these password operations.
The class defaults to using the default algorithm that PHP selects (per version) and a cost of 10. Both can be set when creating the hash.
NOTE: It is recommended that database columns that store hashes created with
password_hash()
are at least 255 characters wide, as the length of hashes will grow in future versions of PHP!
INSTALLING
Via Composer
Run the following command in the same directory as your composer.json file:
php composer.phar require jabarihunt/password
Via Github
-
Clone this repository into a working directory:
git clone [email protected]:jabarihunt/password .
- Include the Password class in your project...
...or if using an auto-loader...
USAGE
The Password::create()
and Password::compare()
methods will throw exceptions if invalid data is passed to them, so be sure to use try/catch blocks!
Creating Password Hashes
Comparing Passwords And Hashes
Using our first hash from above...
Validating Passwords
There is a third method, Password::isValid()
, that validates if a password follows the below rules and returns a boolean
. Eventually I'll add functionallity to pass your own rules. This method doesn't throw any exceptiones.
Password Rules:
- Is not empty
- Contains at least 8 charatcters
- Contains at least 1 uppercase letter
- Contains at least 1 lowercase letter
- Contains at least 1 number
- Contains at least 1 symbol
You can optionally pass a second string
parameter called $username
that will make sure the password does not contain the username (or whatever the passed string contains).
CONTRIBUTING
- Fork Repository
- Create a descriptive branch name
- Make edits to your branch
- Squash (rebase) your commits
- Create a pull request
LICENSE
This project is licensed under the MIT License - see the LICENSE.md file for details