Jump to content
hogava

SMTPPassword how stored in database?

Recommended Posts

Hello,

i need insert smtp setting from phpmyadmin. 

how i should edite SMTPPassword in tblconfiguration ?

md5?

thanks.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

But I want reverse of it. 

i have my gmail password and i need Encrypt password and then save it for SMTPPassword

Share this post


Link to post
Share on other sites

Thanks so much,

How should run this and get result. 

I saved it in PHP file and run it but i have 500 error.

Share this post


Link to post
Share on other sites

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]);

 

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated