Answers.Body: <p>First - you must have command-line access, the <code>cv</code> utility installed, and database access. This also assumes modern CiviCRM, where you have <code>CIVICRM_CRED_KEYS</code> defined in your <code>civicrm.settings.php</code>.</p>
  <p>Check the database for the record that contains your password with the following SQL:</p>
  <pre><code>SELECT REGEXP_SUBSTR(value, 'smtpPassword.*') FROM civicrm_setting WHERE name = 'mailing_backend';
  </code></pre>
  <p>You should get back something like this:</p>
  <pre><code>MariaDB [my_database]&gt; SELECT REGEXP_SUBSTR(value, 'smtpPassword.*') FROM civicrm_setting WHERE name = 'mailing_backend';
  +-------------------------------------------------------------------------------------------------------------------------------+
  | REGEXP_SUBSTR(value, 'smtpPassword.*')                                                                                        |
  +-------------------------------------------------------------------------------------------------------------------------------+
  | smtpPassword&quot;;s:101:&quot;CTK?k=dxBmEYKu9NyzrI1vngkmrxtqUL4&amp;t=NuDgeEtjXFvxYWwAYii0S2GZqSfcpWS5G7d6DF1souXWmxixnQMwrH46tV_oqRLy&quot;;} |
  +-------------------------------------------------------------------------------------------------------------------------------+
  1 row in set (0.000 sec)
  </code></pre>
  <p>The encrypted password is in quotes, starting with <code>CTK</code>.  If it does NOT start with <code>CTK</code>, it's not encrypted - that's your password.</p>
  <p>If it <em>is</em> encrypted, run the following command on your command line:</p>
  <pre><code>cv ev '$k = new \Civi\Crypto\CryptoToken(); $t = $k-&gt;decrypt(&quot;\x02&quot; . &quot;&lt;encrypted password here&gt;&quot;); echo $t'
  </code></pre>
  <p>For instance, using the example above:</p>
  <pre><code>cv ev '$k = new \Civi\Crypto\CryptoToken(); $t = $k-&gt;decrypt(&quot;\x02&quot; . &quot;CTK?k=dxBmEYKu9NyzrI1vngkmrxtqUL4&amp;t=89TTC7izYJ5KemXD4Pf8QckyMKvJ4RJcSQM2ejZPlx0HgUVYQguv_yJJn22QAuri&quot;); echo $t'
  </code></pre>
  <p>The password will be returned on the command line.  Note that you MUST be running this command using the same <code>CIVICRM_CRED_KEYS</code> setting in <code>civicrm.settings.php</code> that existed when the key was encrypted.</p>
  <p>Here's a quick 2-liner that does all this:</p>
  <pre><code>CRYPTEDPW=`echo &quot;SELECT REGEXP_SUBSTR(value, 'smtpPassword.*') FROM civicrm_setting WHERE name = 'mailing_backend';&quot; | cv sql -e | sed -n -e 's/.*\(CTK.*\)&quot;.*/\1/p'`
  cv ev '$k = new \Civi\Crypto\CryptoToken(); $t = $k-&gt;decrypt(&quot;\x02&quot; . &quot;'$CRYPTEDPW'&quot;); echo $t'
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-08-09T19:04:06.610Z
Answers.LastActivityDate: 2024-04-29T16:06:36.950Z
Answers.LastEditDate: 2024-04-29T16:06:36.950Z
Answers.UserDisplayName: Jon G - Megaphone Tech
Answers.Body: <p>Go to the settings form at Administer » System Settings » Outgoing Email. Use your browser's tools to inspect the password field: e.g. in Chrome or Firefox, right-click on the password field and select Inspect. Or view the page source and search for &quot;smtpPassword&quot;. You should see something like this:</p>
  <pre><code>&lt;input name=&quot;smtpPassword&quot; type=&quot;password&quot; value=&quot;mypassword&quot; id=&quot;smtpPassword&quot; class=&quot;crm-form-password&quot; /&gt;
  </code></pre>
  <p>The value is the unencrypted password.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-10-23T10:30:49.763Z
Answers.LastActivityDate: 2024-10-23T10:30:49.763Z
Answers.UserDisplayName: davejenx
Body: <p>I've added a mail account at <strong>Administer » System Settings » Outgoing Email</strong>.  I don't know the password, but I need it.  How can I get ahold of it?</p>
  
Tags: <civimail><passwords>
Title: How can I decrypt a password stored in CiviCRM?
ThreadText: # How can I decrypt a password stored in CiviCRM?
  
  (Asked by: username_0 on 2023-08-09)
  
  I've added a mail account at **Administer » System Settings » Outgoing Email**. I don't know the password, but I need it. How can I get ahold of it?
  
  **Tags:** civimail, passwords
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_0 on 2023-08-09. Score: 3
  
  First - you must have command-line access, the cv utility installed, and database access. This also assumes modern CiviCRM, where you have CIVICRM_CRED_KEYS defined in your civicrm.settings.php.
  Check the database for the record that contains your password with the following SQL:
  SELECT REGEXP_SUBSTR(value, 'smtpPassword.*') FROM civicrm_setting WHERE name = 'mailing_backend';
  
  You should get back something like this:
  MariaDB [my_database]> SELECT REGEXP_SUBSTR(value, 'smtpPassword.*') FROM civicrm_setting WHERE name = 'mailing_backend';
  +-------------------------------------------------------------------------------------------------------------------------------+
  | REGEXP_SUBSTR(value, 'smtpPassword.*')                                                                                        |
  +-------------------------------------------------------------------------------------------------------------------------------+
  | smtpPassword";s:101:"CTK?k=dxBmEYKu9NyzrI1vngkmrxtqUL4&t=NuDgeEtjXFvxYWwAYii0S2GZqSfcpWS5G7d6DF1souXWmxixnQMwrH46tV_oqRLy";} |
  +-------------------------------------------------------------------------------------------------------------------------------+
  1 row in set (0.000 sec)
  
  The encrypted password is in quotes, starting with CTK.  If it does NOT start with CTK, it's not encrypted - that's your password.
  If it is encrypted, run the following command on your command line:
  cv ev '$k = new \Civi\Crypto\CryptoToken(); $t = $k->decrypt("\x02" . ""); echo $t'
  
  For instance, using the example above:
  cv ev '$k = new \Civi\Crypto\CryptoToken(); $t = $k->decrypt("\x02" . "CTK?k=dxBmEYKu9NyzrI1vngkmrxtqUL4&t=89TTC7izYJ5KemXD4Pf8QckyMKvJ4RJcSQM2ejZPlx0HgUVYQguv_yJJn22QAuri"); echo $t'
  
  The password will be returned on the command line.  Note that you MUST be running this command using the same CIVICRM_CRED_KEYS setting in civicrm.settings.php that existed when the key was encrypted.
  Here's a quick 2-liner that does all this:
  CRYPTEDPW=`echo "SELECT REGEXP_SUBSTR(value, 'smtpPassword.*') FROM civicrm_setting WHERE name = 'mailing_backend';" | cv sql -e | sed -n -e 's/.*\(CTK.*\)".*/\1/p'`
  cv ev '$k = new \Civi\Crypto\CryptoToken(); $t = $k->decrypt("\x02" . "'$CRYPTEDPW'"); echo $t'
  
  
  ---
  
  ### Answer by username_1 on 2024-10-23. Score: 1
  
  Go to the settings form at Administer » System Settings » Outgoing Email. Use your browser's tools to inspect the password field: e.g. in Chrome or Firefox, right-click on the password field and select Inspect. Or view the page source and search for "smtpPassword". You should see something like this:
  
  
  The value is the unencrypted password.
  
  
  ---
  
  