Security: How should I store (“Remember”) a user's username and password for future use?

杀马特。学长 韩版系。学妹 提交于 2019-12-05 13:19:46

First, be aware that no method of storing names and passwords locally is going to be secure. Obfuscating and/or encrypting (which I would consider mandatory) will defend against casual snooping, but the data must still be decipherable locally to be useful, and that process can be replicated by a determined hacker. You should always give the user the option of opting out (or opting in) to this scheme. (This is what browsers typically do.)

If you are using the name/password to communicate to a server, a better approach is to obtain an identity token from the server upon successful login and store that locally. That way, even if the encryption is broken, the user's login credentials are not compromised (although access to the account may be, at least until the token is revoked).

EDIT: Since you're targeting Windows, consider using the Data Protection API.

Assuming that you need to store credentials for an external service, such as storing an email account username and password, your only option for secure local storage is to encrypt relevant credentials before writing them to a file.

What method you choose for encryption is a question in it's own right.

Focus your attentions on selecting an encryption mechanism that cannot be brute forced in a reasonable amount of time and selecting an encryption mechanism that permits a straightforward means of setting and changing the key length.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!