To create a field as password type in which input text is abstruse at admin configuration
Use obscure as the field type and
Magento\Config\Model\Config\Backend\Encrypted as the backend_model
<field id='api_secret' translate='label' type='obscure' sortOrder='3' showInDefault='1' showInWebsite='1' showInStore='1'> <label>Api key</label> <backend_model>Magento\Config\Model\Config\Backend\Encrypted</backend_model> </field>

after that you see that in configuration at admin panel a text field is created under name “Api key” and when you put or type some value in it then it will show as a password with dot sign.
Actually, obscure field type encrypts the value of fields.
To get the decrypted value of configuration’s obscure type field we will have to use
\Magento\Framework\Encryption\EncryptorInterface interface
<?php Class Encryptor protected $_enc; public function __construct( \Magento\Framework\Encryption\EncryptorInterface $enc ) { $this->_enc = $enc; parent::__construct($context); } //here $val contain the encrypted configuration value $val = 'asdfgh-erp45dfrtgbnhjlkouojutywer'; $val = $this->_enc->decrypt($val); ?>
Be the first to comment.