* @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; } }