{"id":23,"date":"2014-03-01T00:02:22","date_gmt":"2014-02-28T14:02:22","guid":{"rendered":"http:\/\/thewanderingsysadmin.net\/?p=23"},"modified":"2014-03-01T00:02:37","modified_gmt":"2014-02-28T14:02:37","slug":"whmcs-password-encryption-and-decryption","status":"publish","type":"post","link":"https:\/\/thewanderingsysadmin.net\/?p=23","title":{"rendered":"WHMCS Password Encryption and Decryption"},"content":{"rendered":"<p>So at my work, we just bought out a couple of other hosting companies, and needed to bring all their customer data from WHMCS into our WHMCS install.<\/p>\n<p>We figured &#8216;no problems, WHMCS has a merge tool&#8217;. \u00a0 Yeah, that didn&#8217;t work at all!<\/p>\n<p>So. \u00a0We sat down and wrote one!<\/p>\n<p>Where things almost came unstuck, was transferring passwords. \u00a0WHMCS stores all manner of passwords &#8211; customer passwords, hosting account passwords, even server passwords. \u00a0For that matter, they also store credit card details. \u00a0And they&#8217;re all stored Encrypted!<\/p>\n<p>After discovering\u00a0<a title=\"This helpful class\" href=\"http:\/\/prayuj.googlecode.com\/svn\/trunk\/Prayuj\/wwwroot\/includes\/ThirdParty\/hash_crypt.php\" target=\"_blank\">this helpful class<\/a>, and mucking about for a few hours working out how they use the hash, I was ready to go! Using it is a breeze. \u00a0You just need your cc_encryption_hash from your WHMCS configuration.php, and off you go.<\/p>\n<pre class=\"lang:default decode:true\">&lt;?PHP\r\ninclude('hash_crypt.php');\r\n\/\/ Encryption hash from WHMCS\r\n$cc_encryption_hash='SOmECRAZYLONGHASHROFLCOPTERBBQKTHX';\r\n$key = md5 (md5 ($cc_encryption_hash)) . md5 ($cc_encryption_hash);\r\n$he = new hash_encryption($key);\r\n\r\necho $plaintext $he-&gt;decrypt('JATa2iUqVdzCkBP5RiyitlQlUiACl8UrpJOeGUJO');\r\n?&gt;<\/pre>\n<p>If you were to run this code, it would display &#8216;MyPassword&#8217;.<\/p>\n<p>So in my case, transferring between two WHMCS installations, I use a code block like the following:<\/p>\n<pre class=\"lang:default decode:true\">&lt;?PHP\r\ninclude('hash_crypt.php');\r\n$old_cc_encryption_hash='SOmECRAZYLONGHASHROFLCOPTERBBQKTHX';\r\n$new_cc_encryption_hash='SOMeOtHERLongEnCryptionHashSTRING';\r\n\r\n$oldkey = md5 (md5 ($old_cc_encryption_hash)) . md5 ($old_cc_encryption_hash);\r\n$newkey = md5 (md5 ($new_cc_encryption_hash)) . md5 ($new_cc_encryption_hash);\r\n$he_old = new hash_encryption($oldkey);\r\n$he_new = new hash_encryption($newkey);\r\n\r\n$newpass = $he_new-&gt;encrypt($he_old-&gt;decrypt($oldpass));<\/pre>\n<p>Assuming you had the encrypted password from the old system in $oldpass, you will now have the password for the new system in $newpass.<\/p>\n<p>Hopefully this helps someone! Google was no help at all for re-encrypting the password!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>So at my work, we just bought out a couple of other hosting companies, and needed to bring all their customer data from WHMCS into our WHMCS install. We figured &#8216;no problems, WHMCS has a merge tool&#8217;. \u00a0 Yeah, that didn&#8217;t work at all! So. \u00a0We sat down and wrote one! Where things almost came [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[11,1],"tags":[],"class_list":["post-23","post","type-post","status-publish","format-standard","hentry","category-hosting","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/thewanderingsysadmin.net\/index.php?rest_route=\/wp\/v2\/posts\/23"}],"collection":[{"href":"https:\/\/thewanderingsysadmin.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/thewanderingsysadmin.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/thewanderingsysadmin.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/thewanderingsysadmin.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=23"}],"version-history":[{"count":1,"href":"https:\/\/thewanderingsysadmin.net\/index.php?rest_route=\/wp\/v2\/posts\/23\/revisions"}],"predecessor-version":[{"id":24,"href":"https:\/\/thewanderingsysadmin.net\/index.php?rest_route=\/wp\/v2\/posts\/23\/revisions\/24"}],"wp:attachment":[{"href":"https:\/\/thewanderingsysadmin.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=23"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/thewanderingsysadmin.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=23"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/thewanderingsysadmin.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=23"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}