Magento, Magento 2

Magento 2 : Difference between obscure and password type

Magento 2 Difference between obscure and password type

In this technical blog, we will learn about what is difference between obscure and password type of fields in system configuration in Magento 2. There are so many types of fields in system configuration. Generally, when we need to setup specific value for whole site or some configuration value want to setup at that time, we’ll create field in systme configuration.

Sometimes, we need to save some secret details and want to hide from other admin user. At that time, security is most important part of the work.

Magento 2 provides many type of fields. But, here we are learn about difference of obscure type and password type field.

What is use of obscure type ?

Obscure type is used for display value as secret text. Sometimes, user change value from inspect element and get that secret value.

But, if you’ll use obscure type in field type then, user can’t read your secret value however, user forcefully change type of input field. Obscure type field return asterisk value (‘******’) after change value from inspect element.

syntax :

<field id="secret_key" translate="label" type="obscure" sortOrder="40" showInDefault="1" showInWebsite="1" showInStore="0">

What is use of password type?

Password type also same as obscure type. But, password type field can’t encrypt value as like obscure type. It used for hide value from the field. But, if user change forcefully value from inspect element then, after change they will get value which save in password type.

<field id="password_key" translate="label" type="password" sortOrder="40" showInDefault="1" showInWebsite="1" showInStore="0">

Let’s now create an example :

After that, create app/code/RH/Helloworld/etc/adminhtml/system.xml file and add this below code :

<?xml version="1.0"?>
<!--
/**
 * Created By : Rohan Hapani
 */
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
    <system>
        <tab id="rh" translate="label" sortOrder="10">
            <label>RH</label>
        </tab>
        <section id="helloworld" translate="label" sortOrder="130" showInDefault="1" showInWebsite="1" showInStore="1">
            <label>Hello World</label>
            <tab>rh</tab>
            <resource>RH_Helloworld::helloworld_config</resource>
            <group id="general" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="0" showInStore="0">
                <label>General Configuration</label>
                <field id="secret_key" translate="label" type="obscure" sortOrder="40" showInDefault="1" showInWebsite="1" showInStore="0">
                    <label>Secret Key</label>
                </field>
                <field id="password_key" translate="label" type="password" sortOrder="50" showInDefault="1" showInWebsite="1" showInStore="0">
                    <label>Password Key</label>
                </field>
            </group>
        </section>
    </system>
</config>

Now, enter value in both field and save config. After, change both field type from inspect element. You can see difference of obscure type and password type field.

I hope this blog is easy to understand about difference between obscure and password type in Magento 2. In case, I missed anything or need to add some information, always feel free to leave a comment in this blog, I’ll get back with proper solution 🙂

 

Tagged ,