How to store a password for a desktop client?

3 years ago by TheCee to c/ask_experienced_devs

Hi, by now it seems to be common knowledge that passwords shouldn't be stored in a database. Backend devs generally know to hash and salt and what-not their transmitted passwords. It seems to be well documented.

However, I wasn't exactly able to find such a clear answer for client applications accessing e.g. web APIs. For example, lets assume you were to create a Lemmy desktop application with support for multiple accounts. Ideally, that software would work like a password manager and store its master password as hash only.

However(2), sometimes users like to start said application without entering their password. Like an Email client in pleb mode. Which requires the passwords to be stored somewhere. In this case, what is the best course of action?

load all comments
pileghoff 5 points 3 years ago

I think most applications store it in plain text, but makes sure the file is only readable by the current user. This way, we rely on the protection of the OS, instead of doing it ourselves. (I'm not a desktop app developer, so I might be completely wrong, but I think this is what e.g. Firefox does).

path: 0 1971960, hotness: undefined, score: 5, children: 1
GJdan 5 points 3 years ago

Yeah it's not too rare to store passwords in config files (e.g ~/.config/appname/config.json) usually at least base64 encoded to support special characters. It is usually better to try and store a token instead as they can be revoked or expired. If you have to store a password it might be fun to look into storing it in the system keychain, at least for macos or Linux, not sure if Windows has a keychain.

path: 0 1971960 1973053, hotness: undefined, score: 5, children: 0
ask_experienced_devs
ask_experienced_devs

@programming.dev

login for more options
1517
63
8

Icon base by Delapouite under CC BY 3.0 with modifications to add a gradient

go to feed...