Core Anonymizers
This page list all Anonymizers provided by DbToolsBundle.
EmailAnonymizer
EmailAnonymizer uses a hash function on the original value to make each unique email anonymization reproducible accross tables.
This Anonymizer will fill configured column with value looking like [username]@[domain.tld] where:
[username]is a md5 hash of the pre-anonymization value[domain.tld]is the given domain option (orexample.comby default)
For example contact@makina-corpus.com will give 826464d916e6052ad209037ca71ce324@example.com after anonymization.
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use MakinaCorpus\DbToolsBundle\Attribute\Anonymize;
#[ORM\Entity()]
#[ORM\Table(name: 'customer')]
class Customer
{
// ...
#[ORM\Column(length: 180, unique: true)]
#[Anonymize(type: 'email')]
private ?string $email = null;
// ...
}# config/anonymization.yaml
customer:
email_address: email
#...Or, with the domain option:
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use MakinaCorpus\DbToolsBundle\Attribute\Anonymize;
#[ORM\Entity()]
#[ORM\Table(name: 'customer')]
class Customer
{
// ...
#[ORM\Column(length: 180, unique: true)]
#[Anonymize(type: 'email', options: ['domain' => 'custom-domain.com'])]
private ?string $email = null;
// ...
}# config/anonymization.yaml
customer:
email_address:
anonymizer: email
options: {domain: 'custom-domain.com'}
#...INFO
Email value is salted prior to be hashed using md5 in order to prevent reverse hashing with rainbow tables. Salt is global across the same anonymization run, this means that the same email address anonymized twice will give the same value.
In order to disable the salt, set the use_salt option to false.
WARNING
SQLite does implement MD5() function, neither any hashing function: in order to get around this, the rowid value is used instead which prevent email values anonymization from being reproducible across tables.
PasswordAnonymizer
This Anonymizer give you a way to set the same password for each one of your users. It is based on the Symfony PasswordHasher Component.
Options are :
algorithm: algorithm to use to hash the plain password. (Default isauto).password: plain password that will be set for each row. (Default ispassword)
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use MakinaCorpus\DbToolsBundle\Attribute\Anonymize;
#[ORM\Entity()]
#[ORM\Table(name: 'customer')]
class Customer
{
// ...
/**
* @var string The hashed password
*/
#[ORM\Column]
#[Anonymize(type: 'password')]
private ?string $password = null;
// Or, with options:
/**
* @var string The hashed password
*/
#[ORM\Column]
#[Anonymize(type: 'password', options: ['algorithm' => 'sodium', 'password' => '123456789'])]
private ?string $password = null;
// ...
}# config/anonymization.yaml
customer:
password: password
# Or, with options:
customer:
password:
anonymizer: password
options: {algorithm: 'sodium', password: '123456789'}
#...IntegerAnonymizer
This Anonymizer will fill configured column with a random integer between two values.
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use MakinaCorpus\DbToolsBundle\Attribute\Anonymize;
#[ORM\Entity()]
#[ORM\Table(name: 'customer')]
class Customer
{
// ...
#[ORM\Column]
#[Anonymize(type: 'integer', options: ['min' => 10, 'max' => 99])]
private ?int $age = null;
// ...
}# config/anonymization.yaml
customer:
age:
anonymizer: integer
options: {min: 10, max: 99}
#...FloatAnonymizer
This Anonymizer will fill configured column with a random float between two values and a given precision (default 2).
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use MakinaCorpus\DbToolsBundle\Attribute\Anonymize;
#[ORM\Entity()]
#[ORM\Table(name: 'customer')]
class Customer
{
// ...
#[ORM\Column]
#[Anonymize(type: 'float', options: ['min' => 10, 'max' => 99, 'precision' => 4])]
private ?float $size = null;
// ...
}# config/anonymization.yaml
customer:
size:
anonymizer: float
options: {min: 120, max: 300, precision: 4}
#...Md5Anonymizer
This Anonymizer will fill configured column with a md5 hash of the pre-anonymization value.
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use MakinaCorpus\DbToolsBundle\Attribute\Anonymize;
#[ORM\Entity()]
#[ORM\Table(name: 'customer')]
class Customer
{
// ...
#[ORM\Column(length: 255)]
#[Anonymize(type: 'md5')]
private ?string $myDirtySecret = null;
// ...
}# config/anonymization.yaml
customer:
my_dirty_secret: md5
#...INFO
Hashing a string is not anonymizing it because hash functions have a reproducible output. In order to avoid decrypting data using rainbow tables, a salt will be added by default to string values prior to hashing.
Salt is global across the same anonymization run, which means that same values across the database will all inherit from the same hashed value, keeping things consistent.
In order to disable the salt usage, set the use_salt option to false.
WARNING
SQLite does implement MD5() function, neither any hashing function, this anonymizer cannot be used with SQLite.
StringAnonymizer
This Anonymizer will fill configured column with a random value from a given sample.
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use MakinaCorpus\DbToolsBundle\Attribute\Anonymize;
#[ORM\Entity()]
#[ORM\Table(name: 'customer')]
class Customer
{
// ...
#[ORM\Column(length: 255)]
#[Anonymize(type: 'string', options: ['sample' => ['none', 'bad', 'good', 'expert']])]
private ?string $level = null;
// ...
}# config/anonymization.yaml
customer:
level:
anonymizer: string
options: {sample: ['none', 'bad', 'good', 'expert']}
#...TIP
If you use the same sample multiple times, if you use a large sample or if you use a generated one, it could be more efficient and convinient to create your own custom anonymizer, see the Custom Anonymizers section to learn how to do that.
LastnameAnonymizer
Works like the StringAnonymizer, but with a provided sample of 1000 worldwide lastnames.
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use MakinaCorpus\DbToolsBundle\Attribute\Anonymize;
#[ORM\Entity()]
#[ORM\Table(name: 'customer')]
class Customer
{
// ...
#[ORM\Column(length: 255)]
#[Anonymize('lastname')]
private ?string $lastname = null;
// ...
}# config/anonymization.yaml
customer:
lastname: lastname
#...FirstnameAnonymizer
Works like the StringAnonymizer, but with a provided sample of 1000 worldwide firstnames.
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use MakinaCorpus\DbToolsBundle\Attribute\Anonymize;
#[ORM\Entity()]
#[ORM\Table(name: 'customer')]
class Customer
{
// ...
#[ORM\Column(length: 255)]
#[Anonymize('firstname')]
private ?string $firstname = null;
// ...
}# config/anonymization.yaml
customer:
firstname: firstname
#...AddressAnonymizer
This Anonymizer is multicolumn. It let you anonymize, at once, mutiple columns on one table that represent different parts of a postal address.
Each part will be fill with a coherent random address from a sample of 300 addresses around the world.
Available parts are :
| Part | Definition | Example |
|---|---|---|
country | The country | France |
locality | The locality in which the street address is, and which is in the region | Nantes |
region | The region in which the locality is, and which is in the country | Pays de la Loire |
postal_code | The postal code | 44000 |
street_address | The street address. For example, 5 rue de la Paix | 5 rue de la Paix |
secondary_address | Additional information (apartment, block) | Appartement 310 |
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use MakinaCorpus\DbToolsBundle\Attribute\Anonymize;
#[ORM\Entity()]
#[ORM\Table(name: 'customer')]
#[Anonymize(type: 'address', options: [
'street_address' => 'street',
'secondary_address': 'street_second_line'
'postal_code' => 'zip_code',
'locality' => 'city',
'region' => 'region'
'country' => 'country',
])]
class Customer
{
// ...
#[ORM\Column(length: 255)]
private ?string $street = null;
#[ORM\Column(length: 255)]
private ?string $streetSecondLine = null;
#[ORM\Column(length: 255)]
private ?string $zipCode = null;
#[ORM\Column(length: 255)]
private ?string $city = null;
#[ORM\Column(length: 255)]
private ?string $region = null;
#[ORM\Column(length: 255)]
private ?string $country = null;
// ...
}# config/anonymization.yaml
customer:
address:
target: table
anonymizer: address
options:
street_address: 'street'
secondary_address: 'street_address_2'
postal_code: 'zip_code'
locality: 'city'
region: 'region'
country: 'country'
#...TIP
Note that you don't have to provide a column for each part. You can use this Anonymizer to only anonymize some parts of an address. To do so, remove options you don't want in the example below.