https://medium.com/@lmeyer./get-an-error-free-e-commerce-web-site-using-sentry-b6061264efc8...
Gestion des passwords pour Prestashop 1.7
Introduction
Très souvent, lors du commencement d'un projet e-commerce, je me retrouve à devoir centraliser les nombreux passwords du client.
Il y en a en format papier, dans les e-mails, chez d'autres prestataires etc... Cela devient très vite un casse tête et une perte de temps.
J'ai donc décidé de créer un module Prestashop "Manage Passwords" afin de gérer et centralisé ces derniers.
Si vous n'avez pas les compétences techniques ou que vous voulez gagner du temps je vous propose le module en téléchargement gratuit:
Télécharger ce module GRATUITEMENT
Compatibilité:
Prestashop 1.7.8.7 ou sup
Fonctionnalitées:
- Cryptage des passwords en base de donnée.
- Afficher / Masquer les mots de passe en backoffice
- Ajout d'un champ url de connexion
A faire:
- Permettre d'envoyer la liste des password en pdf par mail
- Permettre au client de récupérer tout ses passwords via son interface
Vue administration
Partie technique
Structure des fichiers
baba_managepasswd.php
<?php
if (!defined('_PS_VERSION_')) {
exit;
}
define('__KEY__', "H%g;d;vYh@gd:78&$32/ndbs&Yte");
require_once __DIR__ . '/classes/ManagePasswd.php';
class baba_managepasswd extends Module
{
public function __construct()
{
$this->name = 'baba_managepasswd';
$this->tab = 'administration';
$this->version = '1.0.0';
$this->author = 'presta.cafe';
$this->need_instance = 0;
/**
* Set $this->bootstrap to true if your module is compliant with bootstrap (PrestaShop 1.6)
*/
$this->bootstrap = true;
parent::__construct();
$this->displayName = $this->l('baba_managepasswd');
$this->description = $this->l('Allow to manage your password');
$this->ps_versions_compliancy = array('min' => '1.7', 'max' => _PS_VERSION_);
}
/**
* Installation du module
* @return bool
*/
public function install()
{
$tab = new Tab();
foreach (Language::getLanguages() as $language) {
$tab->name[$language['id_lang']] = 'Passwords';
}
$tab->class_name = 'AdminManagePasswd';
$tab->module = $this->name;
$idParent = (int)Tab::getIdFromClassName('IMPROVE');
$tab->id_parent = $idParent;
$tab->position = Tab::getNbTabs($idParent);
$tab->icon = 'lock';
if(!$tab->save())
return false;
Configuration::updateValue('BABAMANAGEPASSWD_ADMIN_TAB', $tab->id);
if (!parent::install()
|| !$this->registerHook([
'displayBackOfficeHeader',
'actionObjectManagePasswdAddBefore',
'actionObjectManagePasswdUpdateBefore',
])
|| !ManagePasswd::installSql()
) {
return false;
}
return true;
}
/**
* Désinstallation du module
* @return bool
*/
public function uninstall()
{
if (
!parent::uninstall()
|| !ManagePasswd::uninstallSql()
) {
return false;
}
return true;
}
/**
* Load the configuration form
*/
public function getContent()
{
$output = $this->context->smarty->fetch($this->local_path.'views/templates/admin/configure.tpl');
return $output;
}
public function hookDisplayBackOfficeHeader($params)
{
$this->context->controller->addJs(_MODULE_DIR_.$this->name.'/views/js/baba_adminpassword.js');
$this->context->controller->addCSS(_MODULE_DIR_.$this->name.'/views/css/baba_adminpassword.css', 'all');
$this->context->controller->addCSS('https://cdnjs.cloudflare.com/ajax/libs/MaterialDesign-Webfont/4.7.95/css/materialdesignicons.css', 'all');
}
public function hookactionObjectManagePasswdAddBefore($params) {
$password = $params['object'];
$textPasswd = $password->password;
$encryptedPassword = openssl_encrypt($textPasswd, "AES-128-ECB" ,__KEY__);
$password->password = $encryptedPassword;
}
public function hookactionObjectManagePasswdUpdateBefore($params) {
$password = $params['object'];
$textPasswd = $password->password;
$encryptedPassword = openssl_encrypt($textPasswd, "AES-128-ECB" ,__KEY__);
$password->password = $encryptedPassword;
}
}
classes/ManagePasswd.php
<?php
use Symfony\Component\Filesystem\Exception\IOException;
use Symfony\Component\Filesystem\Filesystem;
if (!defined('_PS_VERSION_')) {
exit;
}
class ManagePasswd extends ObjectModel
{
public $id_baba_managepasswd;
public $name;
public $user_login;
public $password;
public $url;
public $description;
public $date_add;
public $date_upd;
public static $definition = [
'table' => 'baba_managepasswd',
'primary' => 'id_baba_managepasswd',
'fields' => [
'id_baba_managepasswd' => ['type' => self::TYPE_INT, 'validate' => 'isInt', 'length' => 10],
'name' => ['type' => self::TYPE_STRING, 'validate' => 'isCleanHtml', 'length' => 50],
'user_login' => ['type' => self::TYPE_STRING, 'validate' => 'isCleanHtml', 'length' => 50],
'password' => ['type' => self::TYPE_STRING, 'validate' => 'isCleanHtml', 'length' => 50],
'url' => ['type' => self::TYPE_STRING, 'validate' => 'isCleanHtml', 'length' => 255],
'description' => ['type' => self::TYPE_HTML, 'validate' => 'isCleanHtml'],
'date_add' => ['type' => self::TYPE_DATE, 'validate' => 'isDate'],
'date_upd' => ['type' => self::TYPE_DATE,'validate' => 'isDate'],
]
];
public function __construct($id = null,$id_lang = null, $id_shop = null)
{
parent::__construct($id, $id_lang, $id_shop);
}
public function add($autodate = true, $null_values = true)
{
$success = parent::add($autodate, $null_values);
return $success;
}
public function update($nullValues = false)
{
return parent::update(true);
}
public function delete()
{
return parent::delete();
}
public static function installSql(): bool
{
try {
$createTable = Db::getInstance()->execute(
"CREATE TABLE IF NOT EXISTS `"._DB_PREFIX_."baba_managepasswd`(
`id_baba_managepasswd` int(10) NOT NULL AUTO_INCREMENT,
`name` VARCHAR (50),
`user_login` VARCHAR (50),
`password` VARCHAR (50),
`url` VARCHAR (255),
`description` VARCHAR(255),
`date_add` datetime NOT NULL,
`date_upd` datetime NOT NULL,
PRIMARY KEY (`id_baba_managepasswd`)
) ENGINE=InnoDB DEFAULT CHARSET=UTF8;"
);
} catch (PrestaShopException $e) {
return false;
}
return $createTable;
}
public static function uninstallSql()
{
return Db::getInstance()->execute("DROP TABLE IF EXISTS "._DB_PREFIX_."baba_managepasswd");
}
}
controllers/admin/AdminManagePasswdController.php
<?php
require_once (_PS_MODULE_DIR_ . 'baba_managepasswd/classes/ManagePasswd.php');
class AdminManagePasswdController extends ModuleAdminController {
public function __construct() {
$this->bootstrap = true;
$this->table = 'baba_managepasswd';
$this->className = 'ManagePasswd';
$this->deleted = false;
$this->list_no_link = true;
$this->addRowAction('edit');
$this->addRowAction('delete');
$this->context = Context::getContext();
$this->required_database = false;
$this->allow_export = true;
$this->_use_found_rows = true;
$this->_orderBy = 'id_baba_managepasswd';
$this->_orderWay = 'DESC';
$this->fields_list = array(
'id_baba_managepasswd' => array('title' => 'ID', 'align' => 'text-left', 'class' => 'fixed-width-xs'),
'name' => array('title' => 'Nom', 'search' => true,),
'user_login' => array('title' => 'login', 'search' => true, 'callback' => 'printLogin',),
'password' => array('title' => 'password', 'search' => false, 'callback' => 'printPasswd',),
'url' => array('title' => 'url', 'search' => false, 'callback' => 'printUrl',),
'description' => array('title' => 'Description', 'search' => false,),
);
parent::__construct();
}
public function initContent() {
parent::initContent();
}
public function setMedia($isNewTheme = false)
{
parent::setMedia();
}
public function renderForm() {
if (!($obj = $this->loadObject(true))) {
return;
}
$key = "H%g;d;vYh@gd:78&$32/ndbs&Yte";
$decrypted_chaine = openssl_decrypt($obj->password, "AES-128-ECB" ,$key);
$obj->password = $decrypted_chaine;
$this->fields_form = array('legend' => array('title' => 'Password', 'icon' => 'icon-user'),
'input' => array(
array(
'type' => 'text',
'label' => 'Nom',
'name' => 'name',
'required' => true,
'col' => '4'
),
array(
'type' => 'text',
'label' => 'login',
'name' => 'user_login',
'required' => true,
'col' => '4'
),
array(
'type' => 'text',
'label' => 'password',
'name' => 'password',
'required' => true,
'col' => '4'
),
array(
'type' => 'text',
'label' => 'url',
'name' => 'url',
'required' => false,
'col' => '6'
),
array(
'type' => 'textarea',
'label' => 'Description',
'name' => 'description',
'required' => false,
'cols' => 40,
'rows' => 10,
),
));
$this->fields_form['submit'] = array('title' => $this->l('Save'),);
return parent::renderForm();
}
public function initToolbarTitle() {
parent::initToolbarTitle();
switch ($this->display) {
case '':
case 'list':
array_pop($this->toolbar_title);
$this->toolbar_title[] = 'Gestion de passwords';
break;
case 'view':
if (($babaPassword = $this->loadObject(true)) && Validate::isLoadedObject($babaPassword)) {
$this->toolbar_title[] = sprintf('Editer password:');
}
break;
case 'add':
case 'edit':
array_pop($this->toolbar_title);
if (($babaPassword = $this->loadObject(true)) && Validate::isLoadedObject($babaPassword)) {
$this->toolbar_title[] = sprintf('Editer password:');
$this->page_header_toolbar_btn['new_baba_managepasswd'] = array('href' => self::$currentIndex . '&addbaba_managepasswd&token=' . $this->token, 'desc' => $this->l('Ajouter un nouveau password', null, null, false), 'icon' => 'process-icon-new');
} else {
$this->toolbar_title[] = 'Créer un nouveau password';
}
break;
}
array_pop($this->meta_title);
if (count($this->toolbar_title) > 0) {
$this->addMetaTitle($this->toolbar_title[count($this->toolbar_title) - 1]);
}
}
public function initPageHeaderToolbar() {
parent::initPageHeaderToolbar();
if (empty($this->display)) {
$this->page_header_toolbar_btn['new_baba_managepasswd'] = array('href' => self::$currentIndex . '&addbaba_managepasswd&token=' . $this->token, 'desc' => $this->l('Ajouter un nouveau password', null, null, false), 'icon' => 'process-icon-new');
}
}
public function printPasswd($value, $tr) {
$key = "H%g;d;vYh@gd:78&$32/ndbs&Yte";
$decrypted_chaine = openssl_decrypt($value, "AES-128-ECB" ,$key);
return '
<div class="input-group">
<input type="password" value="'.$decrypted_chaine.'" class="form-control" name="password" autocomplete="new-password" minlength="6">
<div class="material-icons input-group-append toggle-password">
<span class="input-group-text mdi mdi-eye-outline"></span>
</div>
</div>
';
}
public function printLogin($value, $tr) {
return '
<input type="text" value="'.$value.'" class="form-control">
';
}
public function printUrl($value, $tr) {
return '<a href="'. $value .'">'. $value .'</a>';
}
}
Publié dans:
SECURITÉ Prestashop
Laissez un commentaire