Simply handle password encryption and salt generation.
PHP
Latest commit 7b92e12 Oct 24, 2016 @polc polc committed on GitHub Merge pull request #17 from KnpLabs/feature/replace-hackzilla-by-uniqid
Remove hackzilla implementation
Permalink
Failed to load latest commit information.
spec/Knp/Rad/User
src/Knp/Rad/User
.gitignore First implementation of password and salt generation Dec 18, 2014
.php_cs
.travis.yml
README.md
composer.json Remove hackzilla implementation Oct 24, 2016
phpspec.yml

README.md

Rapid Application Development : User

Simply handle password encryption and salt generation

Build Status Scrutinizer Code Quality Latest Stable Version Total Downloads Latest Unstable Version License

Installation

composer require knplabs/rad-user:~2.0
class AppKernel
{
    function registerBundles()
    {
        $bundles = array(
            //...
            new Knp\Rad\User\Bundle\UserBundle(),
            //...
        );

        //...

        return $bundles;
    }
}

Usages

I want to auto-generate my user salt

Your User model should implement the Knp\Rad\User\HasSalt interface.


namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;
use Knp\Rad\User\HasSalt;

/**
 * @ORM\Entity
 */
class User implements HasSalt
{
    use HasSalt\HasSalt; //You can also use this trait

    /**
     * @ORM\Id
     * @ORM\GeneratedValue
     * @ORM\Column(type="integer")
     */
    private $id;

    /**
     * @ORM\Column
     */
    private $salt;
}

Now, before your user is inserted into your database, the salt will be auto-generated.

I want to auto-generate my user password

Your User model should implement the Knp\Rad\User\HasInitialPassword interface.


namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;
use Knp\Rad\User\HasInitialPassword;

/**
 * @ORM\Entity
 */
class User implements HasInitialPassword
{
    use HasInitialPassword\HasInitialPassword; // You can also use this trait

    /**
     * @ORM\Id
     * @ORM\GeneratedValue
     * @ORM\Column(type="integer")
     */
    private $id;

    /**
     * @ORM\Column
     */
    private $password;
}

Now, before your user is inserted or updated into your database, then the plain password will be automaticly generated.

I want to auto-encode my user password

Your User model should implement the Knp\Rad\User\HasPassword interface.


namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;
use Knp\Rad\User\HasPassword;

/**
 * @ORM\Entity
 */
class User implements HasPassword
{
    use HasPassword\HasPassword; // You can also use this trait

    /**
     * @ORM\Id
     * @ORM\GeneratedValue
     * @ORM\Column(type="integer")
     */
    private $id;

    /**
     * @ORM\Column
     */
    private $password;
}

Now, before your user is inserted or updated into your database, if you have set the attribute 'plainPassword', then the password will be automaticly generated.

WARNING

The Knp\Rad\User\HasPassword\HasPassword trait use the Knp\Rad\User\HasInitialPassword\HasInitialPassword trait. So don't use both into the same class or you will have a method conflict.

Some tips

Change the salt generator

You can use your own salt generator. You just have to declare a service implementing the Knp\Rad\User\Salt\Generator interface and tag it with knp_rad_user.salt_generator.

Change the initial password generator

You can change the default password generator. By default, the rad-users uses the hackzilla/password-generator. You can chenga it by implementing the Knp\Rad\User\Password\Generator interface and tag the service with the knp_rad_user.password_generator tag.

Using with MongoDB or CouchDB Object Document Mapper

The knp/rad-user library is also compatible with MongoDB and CouchDB