hogava Posted January 8, 2020 Share Posted January 8, 2020 Hello, i need insert smtp setting from phpmyadmin. how i should edite SMTPPassword in tblconfiguration ? md5? thanks. 0 Quote Link to comment Share on other sites More sharing options...
DennisHermannsen Posted January 8, 2020 Share Posted January 8, 2020 You can use the DecryptPassword API function to decrypt it: https://developers.whmcs.com/api-reference/decryptpassword/ Something like this <?php include_once 'init.php'; $SMTPPassword = Capsule::table('tblconfiguration')->value('SMTPPassword'); $command = 'DecryptPassword'; $postData = array( 'password2' => $SMTPPassword, ); $results = localAPI($command, $postData); print_r($results); The code above is not tested, but something like that would work for you. 1 Quote Link to comment Share on other sites More sharing options...
hogava Posted January 8, 2020 Author Share Posted January 8, 2020 But I want reverse of it. i have my gmail password and i need Encrypt password and then save it for SMTPPassword. 0 Quote Link to comment Share on other sites More sharing options...
DennisHermannsen Posted January 8, 2020 Share Posted January 8, 2020 Ah, okay. Use the EncryptPassword function instead: https://developers.whmcs.com/api-reference/encryptpassword/ 1 Quote Link to comment Share on other sites More sharing options...
hogava Posted January 8, 2020 Author Share Posted January 8, 2020 Thanks so much, How should run this and get result. I saved it in PHP file and run it but i have 500 error. 0 Quote Link to comment Share on other sites More sharing options...
DennisHermannsen Posted January 8, 2020 Share Posted January 8, 2020 Sorry, I forgot to include Capsule. Use this: <?php use WHMCS\Database\Capsule; require __DIR__ . '/init.php'; $gmailPassword = "MyPassword"; $command = 'EncryptPassword'; $postData = array( 'password2' => $gmailPassword, ); $results = localAPI($command, $postData); print_r($results); $results['password'] contains your password en encrypted format. You can insert this into the database like this: <?php use WHMCS\Database\Capsule; require __DIR__ . '/init.php'; $gmailPassword = "MyPassword"; $command = 'EncryptPassword'; $postData = array( 'password2' => $gmailPassword, ); $results = localAPI($command, $postData); $newPass = $results['password']; $changePassword = Capsule::table('tblconfiguration')->where('setting', 'SMTPPassword')->update(['value' => $newPass]); 1 Quote Link to comment Share on other sites More sharing options...
hogava Posted July 30, 2020 Author Share Posted July 30, 2020 This function changed recently? 0 Quote Link to comment Share on other sites More sharing options...
hogava Posted August 1, 2020 Author Share Posted August 1, 2020 with this method, any time that i refresh page, i get new value! 0 Quote Link to comment Share on other sites More sharing options...
DennisHermannsen Posted August 3, 2020 Share Posted August 3, 2020 Could you share your code here? 0 Quote Link to comment Share on other sites More sharing options...
Kian Posted August 3, 2020 Share Posted August 3, 2020 On 8/1/2020 at 11:33 AM, hogava said: with this method, any time that i refresh page, i get new value! Probably you are running the code on every page load. 0 Quote Link to comment Share on other sites More sharing options...
DennisHermannsen Posted August 3, 2020 Share Posted August 3, 2020 9 minutes ago, Kian said: Probably you are running the code on every page load. If he's using the DecryptPassword function, he should still get the same value - right? 0 Quote Link to comment Share on other sites More sharing options...
Kian Posted August 3, 2020 Share Posted August 3, 2020 Yes, DecryptPassword always returns the original password. On the other hand EncryptPassword always returns a different value. $results = localAPI('EncryptPassword', array('password2' => 'aaa')); echo "<pre>"; print_r($results); echo "</pre>"; $results = localAPI('DecryptPassword', array('password2' => $results['password'])); echo "<pre>"; print_r($results); echo "</pre>"; If you run the above script 3 times you'll get the following. 1st run Array ( [result] => success [password] => 56Caa8prWCL/Y5rAie/0bfOAlMDoYMk= ) Array ( [result] => success [password] => aaa ) 2nd run Array ( [result] => success [password] => 9z1gjm1s8mjLhVNzMoTh42QaAoj4/TM= ) Array ( [result] => success [password] => aaa ) 3rd run Array ( [result] => success [password] => xYg2vuJuYMdMcYShOPKO/4wKXrzKSGU= ) Array ( [result] => success [password] => aaa ) That's why I suspect @hogava is referring to EncryptPassword. 0 Quote Link to comment Share on other sites More sharing options...
weba Posted December 16, 2021 Share Posted December 16, 2021 I am storing a value encrypted with the WHMCS API function in the tblusers table password field. When I use the decrypt function my original value is visible but I cannot login with it. Does it work for the tblusers table ? 0 Quote Link to comment Share on other sites More sharing options...
string Posted December 16, 2021 Share Posted December 16, 2021 9 hours ago, weba said: Does it work for the tblusers table ? EncryptPassword / DecryptPassword does not work with user passwords, these passwords are stored as one-way hashes in the database. These hashes can not be decrypted. And EncryptPassword can not be used to set a user password. Passwords like the SMTP password are stored using a two-way encryption, because WHMCS must be able to get the real password to login to the SMTP server. 0 Quote Link to comment Share on other sites More sharing options...
weba Posted December 17, 2021 Share Posted December 17, 2021 Hi! thx for your reply, I did not need to decrypt the password but only store a new one in the tblusers table. I found out that storing it in the Database with the php function password_hash works 🙂 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.