--- title: Encrypt Attributes extends: _layouts.documentation section: content --- # Encrypt Tenant Attributes {#encrypt} We can encrypt the tenant attributes if needed. In the example below, We will encrypt the database username and password. # Encrypt Tenant Username And Password {#encrypt-username-password} When resolving the tenant's database configuration, this package is using the values in the `data` column stored as `tenancy_db_username` and `tenancy_db_password` to create the values used in the db config as `username` and `password`, respectively. So the Tenancy package is looking in the [Virtual Column](https://github.com/archtechx/virtualcolumn) for `tenancy_db_username` and `tenancy_db_password`. The package provides a place in the migrations for your own custom columns and a method to tell the model that it should be looking for the data in an actual database column instead of the virtual column. This means, we can do this: ```php string('id')->primary(); // Your custom columns $table->string('tenancy_db_username', 512); $table->string('tenancy_db_password', 512); $table->timestamps(); $table->json('data')->nullable(); }); } } ``` To create the columns in the database. Then let the model know about them And combine this with [Laravel encrypted casts](https://laravel.com/docs/9.x/eloquent-mutators#encrypted-casting) (or, better yet, a custom cast) to encrypt and decrypt these when needed: ```php 'encrypted', 'tenancy_db_password' => 'encrypted', ]; /** * Define custom columns for this model (that shouldn't be accessed via 'data' property). * * @return array */ public static function getCustomColumns(): array { return [ 'id', 'tenancy_db_username', 'tenancy_db_password', ]; } } ```