Jump to content

SMTPPassword how stored in database?


hogava

Recommended Posts

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.

Link to comment
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]);

 

Link to comment
Share on other sites

  • 6 months later...

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.

Link to comment
Share on other sites

  • 1 year later...
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.

Link to comment
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