Download the PHP package cpliakas/doctrine-password without Composer
On this page you can find all versions of the php package cpliakas/doctrine-password. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download cpliakas/doctrine-password
More information about cpliakas/doctrine-password
Files in cpliakas/doctrine-password
Package doctrine-password
Short Description Adds a password type to Doctrine that hashes and compares passwords using the phpass library.
License GPL-3.0
Homepage https://github.com/cpliakas/doctrine-password
Informations about the package doctrine-password
Doctrine Password Type
This project provides a password type for Doctrine that automatically hashes passwords using the PHP Password Library and provides a helper method to compare them to raw data submitted by end users. The primary goal is to make it stupid-simple to store hashed passwords in a database and check if passwords submitted by end users are valid.
Installation
This library can be installed with Composer. Define the following
requirement in your project's composer.json
file:
Then follow Composer's Installation / Usage guide to install this library.
Usage
This library assumes that the developer is familiar with Doctrine ORM, otherwise the code snippets below won't make much sense.
First, define your entity. Use the "password" type for the column storing passwords:
Then write your code to obtain the EntityManager, and register the password type:
Next, configure the command line tool and use it to create your schema:
Now you are ready to add a user to the system. In the example below we will set the raw password, and the library will automatically hash it when written to the database.
The password is now stored as a hash in the database. When retrieving the user from the database, the password is returned as an object that contains a helper method to compare raw passwords submitted by end users: