I'm writing a small program with PyQt and python 3.
The program needs to know the username and password for a user's email account to use for POP3 protocol. And I wonder what's the best and hopefully not too complicated practice to store those things?
Thanks.
As far as I know, Qt doesn't offer anything to store passwords securely.
But you can look at python keyring library, it should allow you to access whichever "password storage vault" is available on the system, use an encrypted file through PyCrypto, or store the password unencrypted.
For C++ I would do the following, you can adjust it to python
Let
QString username
QString password
The strings that the user enters on line edits,
// Encrypt the password using SHA1
QByteArray passHash = QCryptographicHash::hash(password.toUtf8(),QCryptographicHash::Sha1 );
QString passHashString(passHash.toHex());
Then use QSettings or whatever you want to store the pair of username and the hashed password.
Every time a user attempts to use the application you can hash the password he provides for a username and compare it to the stored one.
Notice that using this approach the password has to be entered every time your application is executed. But in my opinion this is safer than storing the password in plain text.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With