如何在 admincontroller 字段表单中加密密码:prestashop
How to encrypt password in admincontroller fields form : prestashop
我正在开发 prestashop.from 中的新模块,此模块可以创建新的用户帐户,并且该表单中有一个密码字段。
此密码字段在数据库中保存纯文本,但我想将该密码保存为哈希 password.this 是我的 fields_form
public function renderForm() {
$this->fields_form = [
'tinymce' => true,
'legend' => [
'title' => $this->l('Edit'),
],
'input' => [
[
'type' => 'text',
'label' => $this->l('User name'),
'name' => 'username',
'size' => 40,
'lang' => false,
'required' => true,
],
[
'type' => 'password',
'label' => $this->l('Password:'),
'name' => 'password_hash',
'size' => 40,
'lang' => false,
'required' => true,
],
],
,
'submit' => [
'title' => $this->l('Save'),
'class' => 'btn btn-default pull-right'
]
];
if (!($obj = $this->loadObject(true)))
return;
return parent::renderForm();
}
您可以获取所有数据并在其中编码字符串:
<?php
public function postProcess()
{
if (Tools::isSubmit('password_hash')) {
$raw_password = Tools::getValue('password_hash');
// Encrypt here and save
}
}
我正在开发 prestashop.from 中的新模块,此模块可以创建新的用户帐户,并且该表单中有一个密码字段。
此密码字段在数据库中保存纯文本,但我想将该密码保存为哈希 password.this 是我的 fields_form
public function renderForm() {
$this->fields_form = [
'tinymce' => true,
'legend' => [
'title' => $this->l('Edit'),
],
'input' => [
[
'type' => 'text',
'label' => $this->l('User name'),
'name' => 'username',
'size' => 40,
'lang' => false,
'required' => true,
],
[
'type' => 'password',
'label' => $this->l('Password:'),
'name' => 'password_hash',
'size' => 40,
'lang' => false,
'required' => true,
],
],
,
'submit' => [
'title' => $this->l('Save'),
'class' => 'btn btn-default pull-right'
]
];
if (!($obj = $this->loadObject(true)))
return;
return parent::renderForm();
}
您可以获取所有数据并在其中编码字符串:
<?php
public function postProcess()
{
if (Tools::isSubmit('password_hash')) {
$raw_password = Tools::getValue('password_hash');
// Encrypt here and save
}
}