Created
July 3, 2016 15:31
-
-
Save richardhj/96fc97fc6ed2082b73d189b3a9d8d978 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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