PHP code example of cpliakas / doctrine-password

1. Go to this page and download the library: Download cpliakas/doctrine-password library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

cpliakas / doctrine-password example snippets

 php

// src/User.php

/** @Entity **/
class User
{
    /**
     * @Id @Column(type="integer")
     * @GeneratedValue(strategy="IDENTITY")
     */
    private $id;

    /** @Column(length=255, unique=true, nullable=false) **/
    private $email;

    /** @Column(type="password", nullable=false) **/
    private $password;

    public function setEmail($email)
    {
        $this->email = $email;
    }
    
    public function setPassword($password)
    {
        $this->password = $password;
    }
    
    public function getPassword()
    {
        $return this->password;
    }
}

 php

// bootstrap.php

use Doctrine\DBAL\Types\Type;

ctrine docs)

Type::addType('password', 'Cpliakas\Password\Doctrine\PasswordType');


php vendor/bin/doctrine orm:schema-tool:create
 php


// Replace with your own project's bootstrap file.
ityManager.
$em = GetEntityManager();

$user = new User();
$user
    ->setEmail('[email protected]')
    ->setPassword('mypassword')
;

$em->persist($user);
$em->flush();

 php


// Replace with your own project's bootstrap file.
ityManager.
$em = GetEntityManager();

$repository = $em->getRepository('User');
$user = $repository->findOneBy(array('email' => '[email protected]'));

// Returns true.
$user->getPassword()->match('mypassword');

// Returns false.
$user->getPassword()->match('badpassword');