Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:
$ composer require querdos/qpass-db-bundle "^1.0"
This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.
Then, enable the bundle by adding it to the list of registered bundles
in the app/AppKernel.php
file of your project:
<?php
// app/AppKernel.php
// ...
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = array(
// ...
new \Querdos\QPassDbBundle\QPassDbBundle(),
);
// ...
}
// ...
}
For now, only one engine is supported:
More support will come as soon as possible.
First of all, update your database schema:
$ bin/console doctrine:schema:update --force
Or if you use the DoctrineMigrationBundle
, run the following commands:
$ bin/console doctrine:migration:diff && bin/console doctrine:migration:migrate
You can now setup your configuration file and specify these following options:
# app/config/config.yml
# QPassDbBundle configuration
q_pass_db:
# Directory where databases will be stored
db_dir: web/database_storage
You can use the main service qpdb.util.pass_db
to create a database:
<?php
// your logic
// retrieve the container
$container = ...;
// create and retrieve the database informations
$qdatabase = $container->get('qpdb.util.pass_db')->create_database($db_name, $password);
You can use the QDatabaseManager
service (qpdb.manager.qdatabase
) to search an existing database:
<?php
// your logic
// retrieve the container
$container = ...;
$db_name = 'db_name_test';
// retrieve a database
$qdatabase = $container->get('qpdb.manager.qdatabase')->readByDatabaseName($db_name);
The manager will return a null value if no database is found.
To do so, you can call the add_password
method from the main service by specifying a QDatabase
, its associated
password, the password to add and finally a label:
<?php
// your logic
// retrieve the container
$container = ...;
// retrieve a database
$qdatabase = $container->get('qpdb.manager.qdatabase')->readByDatabaseName($db_name);
// add a new password
$qpassword = $container->get('qpdb.util.pass_db')->add_password($qdatabase, $password, $pass_to_add, $label);
You will need a pass_id
in order to retrieve a password. To do so:
<?php
// your logic
// retrieve the container
$container = ...;
// retrieve a database
$qdatabase = $container->get('qpdb.manager.qdatabase')->readByDatabaseName($db_name);
// If no QPassword match, the manager will return a null value
$qpassword = $container->get('qpdb.manager.qpassword')->readByPassId($pass_id);
// If you want to access the password:
$password_value = $container->get('qpdb.util.pass_db')->get_password($qdatabase, $password, $qpassword);
You can use the main service in order to perform this operation:
<?php
// your logic
// retrieve the container
$container = ...;
// retrieve a database
$qdatabase = $container->get('qpdb.manager.qdatabase')->readByDatabaseName($db_name);
// retrieve all passwords
$passwords = $container->get('qpdb.util.pass_db')->get_all_password($qdatabase, $password);
/*
* The result will be an array with the list of passwords with their associated pass_id
* array => [
* 'pass_id_1' => 'password_1',
* 'pass_id_2' => 'password_2'
* ]
*/
<?php
// your logic
// retrieve the container
$container = ...;
// retrieve a database
$qdatabase = $container->get('qpdb.manager.qdatabase')->readByDatabaseName($db_name);
// retrieve a password
$qpassword = $container->get('qpdb.manager.qpassword')->readByPassId($pass_id);
// finally remove it
$container->get('qpdb.util.pass_db')->remove_password($qdatabase, $password, $qpassword);
<?php
// your logic
// retrieve the container
$container = ...;
// retrieve a database
$qdatabase = $container->get('qpdb.manager.qdatabase')->readByDatabaseName($db_name);
// finally remove it
$container->get('qpdb.util.pass_db')->remove_database($qdatabase, $password);