Have you seen our new video tutorials? Check it out!

Encrypted Field Type

The encrypted field type provides an encrypted value input.

Introduction

anomaly.field_type.encrypted

The encrypted field type provides a password input that stores the value as an encrypted string.

Configuration

Below is the full configuration available with defaults values:

"example" => [
    "type"   => "anomaly.field_type.encrypted",
    "config" => [
        "default_value" => null,
        "show_text"    => false,
        "auto_decrypt" => false
    ]
]
Configuration
Key Example Description

default_value

Secret Password

The defualt value.

show_text

true

Display plain text by default when typing in the input.

auto_decrypt

true

Define whether the value is automatically decrypted when accessed or not.

Usage

This section will show you how to use the field type via API and in the view layer.

Setting Values

You can set the encrypted field type value with a string.

$entry->example = "secret";

Basic Output

The editor field type returns the encrypted value unless auto_decrypt is enabled.

$entry->example; // YzJWamNtVjBEUW89IFl6SldhbU50VmpCRVVXODk=

Presenter Output

This section will show you how to use the decorated value provided by the \Anomaly\EncryptedFieldType\EncryptedFieldTypePresenter class.

EncryptedFieldTypePresenter::decrypt()

The decrypt method decrypts the value.

Returns: string
Example
$decorated->example->decrypt();
Twig
{{ decorated.example.decrypt() }}

EncryptedFieldTypePresenter::hash()

The hash method returns a hash of the decrypted value. This is nice for comparing encrypted values without exposing them.

Returns: string
Arguments
Key Required Type Default Description

$algorithm

false

string

md5

The hashing algorithm to use. Valid options vary by machine.

Example
$decorated->example->hash('sha256');
Twig
{{ decorated.example.hash('sha256') }}

EncryptedFieldTypePresenter::md5()

The md5 method maps to hash('md5').

Returns: string
Example
$decorated->example->md5();
Twig
{{ decorated.example.md5() }}

EncryptedFieldTypePresenter::sha1()

The sha1 method maps to hash('sha1').

Returns: string
Example
$decorated->example->sha1();
Twig
{{ decorated.example.sha1() }}

EncryptedFieldTypePresenter::sha265()

The sha256 method maps to hash('sha256').

Returns: string
Example
$decorated->example->sha256();
Twig
{{ decorated.example.sha256() }}

EncryptedFieldTypePresenter::__value()

The __value method is used in various areas of the system and maps to decrypt.

Arguments
Key Required Type Default Description

$collection

true

string

none

The collection to add the asset to.