Skip to content

Instantly share code, notes, and snippets.

@richardhj
Created July 3, 2016 15:31
Show Gist options
  • Save richardhj/96fc97fc6ed2082b73d189b3a9d8d978 to your computer and use it in GitHub Desktop.
Save richardhj/96fc97fc6ed2082b73d189b3a9d8d978 to your computer and use it in GitHub Desktop.
<?php
/**
* Exemplified DCA config for a password field for Contao Open Source CMS
* The password will be
* * saved encrypted in the database ('encrypt'=>true),
* * invisibe when typing in the input ('hideInput'=>true) and
* * not readable in the html source code after it was saved initially (load_ and save_callback).
*
* @author Richard Henkenjohann <richardhenkenjohann@googlemail.com>
*/
$table = 'tl_my_module';
/**
* DCA config
*/
$GLOBALS['TL_DCA'][$table] = array
(
// Fields
'fields' => array
(
'password' => array
(
'label' => &$GLOBALS['TL_LANG'][$table]['password'],
'exclude' => true,
'inputType' => 'text',
'eval' => [
'mandatory' => true,
'encrypt' => true,
'hideInput' => true,
'preserveTags' => true,
'tl_class' => 'w50',
],
'load_callback' => function ($value) {
if (strlen($value)) {
return \Encryption::encrypt('*****');
}
return $value;
},
'save_callback' => function ($value, \DataContainer $dc) {
if ('*****' === \Encryption::decrypt($value)) {
return $dc->activeRecord->password;
}
return $value;
},
'sql' => "text NULL",
),
),
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment