Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the best practice to store password and username in a PyQt program?

Tags:

python-3.x

qt

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.

like image 943
Derrick Zhang Avatar asked Feb 22 '23 12:02

Derrick Zhang


2 Answers

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.

like image 100
alexisdm Avatar answered Apr 29 '23 12:04

alexisdm


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.

like image 27
pnezis Avatar answered Apr 29 '23 12:04

pnezis