Storing a service account with Flask-SQLAlchemy
<p>I'm writing a small HipChat plugin using Flask and Flask-SQLAlchemy with local database. I want the admin to be able to setup a service account for an external service this is meant to integrate with.</p>

<p>Because the username/password of the service accounts needs to be stored so they can be used by the integration to make API calls I can't use non-reversible hashing methods for storing the password.</p>

<p>Are there recommendations for how to approach this so that the passwords or the database can be better secured?</p>

<p>You can encrypt your data before storing them in your database. <a href="https://www.dlitz.net/software/pycrypto/" rel="nofollow"><code>pycrypto</code></a> is one of the libraries that you can utilize.</p>

<blockquote>
  <p>It is easy to encrypt text using DES/ECB with pycrypto. The key
  â10234567â is 8 bytes and the textâs length needs to be a multiple of
  8 bytes. We picked âabcdefghâ in this example.</p>
</blockquote>

<pre><code>&gt;&gt;&gt; from Crypto.Cipher import DES
&gt;&gt;&gt; des = DES.new('01234567', DES.MODE_ECB)
&gt;&gt;&gt; text = 'abcdefgh'
&gt;&gt;&gt; cipher_text = des.encrypt(text)
&gt;&gt;&gt; cipher_text
'\xec\xc2\x9e\xd9] a\xd0'
&gt;&gt;&gt; des.decrypt(cipher_text)
'abcdefgh'
</code></pre>

<p><a href="http://www.laurentluce.com/posts/python-and-cryptography-with-pycrypto/#a_2" rel="nofollow">here</a> is a short article about <code>pycrypto</code>.</p>

python security password-encryption