chocolatdemariage/www/modules/tntofficiel/libraries/TNTOfficiel_PasswordManager.php

64 lines
1.8 KiB
PHP
Raw Normal View History

2017-09-12 10:48:51 +02:00
<?php
/**
* TNT OFFICIAL MODULE FOR PRESTASHOP
*
* @author GFI Informatique <www.gfi.fr>
* @copyright 2016-2017 GFI Informatique, 2016-2017 TNT
* @license https://opensource.org/licenses/MIT MIT License
*/
require_once _PS_MODULE_DIR_.'tntofficiel/libraries/TNTOfficiel_Debug.php';
class TNTOfficiel_PasswordManager
{
static $salt = '0hp6df7j46df4gc6df42nfhf6i9gfdzz';
/**
* Encrypt password
* @param $password
* @return string
*/
public static function encrypt($password)
{
TNTOfficiel_Debug::log(array('msg' => '>>', 'file' => __FILE__, 'line' => __LINE__));
$encryptedPwd = trim(base64_encode(mcrypt_encrypt(
MCRYPT_RIJNDAEL_256, TNTOfficiel_PasswordManager::$salt, $password, MCRYPT_MODE_ECB,
mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_RAND)
)));
return $encryptedPwd;
}
/**
* Decrypt password
* @param $password
* @return string
*/
public static function decrypt($password)
{
TNTOfficiel_Debug::log(array('msg' => '>>', 'file' => __FILE__, 'line' => __LINE__));
$decryptedPwd = trim(mcrypt_decrypt(
MCRYPT_RIJNDAEL_256, TNTOfficiel_PasswordManager::$salt, base64_decode($password), MCRYPT_MODE_ECB,
mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_RAND)
));
return $decryptedPwd;
}
/**
* get a sha1 hash of the password
* @return string
*/
public static function getHash()
{
TNTOfficiel_Debug::log(array('msg' => '>>', 'file' => __FILE__, 'line' => __LINE__));
$hashedPwd = sha1(TNTOfficiel_PasswordManager::decrypt(Configuration::get('TNT_CARRIER_PASSWORD')));
return $hashedPwd;
}
}