自定义Magento管理员配置密码加密

时间:2012-11-29 15:21:36

标签: magento password-encryption

我需要sftp服务器的密码作为我正在处理的Magento模块的配置字段。添加字段非常简单,但Magento实际上并没有加密该值只是因为frontend_type password。{/ p>

<sftp_password translate="label">
    <label>SFTP Password</label>
    <frontend_type>password</frontend_type>
    <sort_order>170</sort_order>
    <show_in_default>1</show_in_default>
    <show_in_website>1</show_in_website>
    <show_in_store>1</show_in_store>
</sftp_password>

我无法找到有关如何正确加密此值的文档。如何在密码存储在数据库中时确保密码加密?

1 个答案:

答案 0 :(得分:14)

<sftp_password translate="label">
      <label>SFTP Password</label>
       <frontend_type>obscure</frontend_type>
      <backend_model>adminhtml/system_config_backend_encrypted</backend_model>
      <sort_order>10</sort_order>
      <show_in_default>1</show_in_default>
      <show_in_website>1</show_in_website>
      <show_in_store>0</show_in_store>
</sftp_password>

// assuming that getConfigData return Mage::getStoreConfig($path, $storeId);
$this->getConfigData('sftp_password'); 

frontend_type:密码v.s Obscure

隐藏扩展密码,但出于安全原因,它会将'*'s的实际密码长度替换为6 '*'s,因此您无法确定密码的长度

参见/ lib / Varien / Data / Form / Element /

了解更多@ XML for Admin Configurations