Android:存储用户名和密码? [英] Android: Storing username and password?

查看:47
本文介绍了Android:存储用户名和密码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我想存储要在 Android 应用程序中使用的用户名和密码,最好的方法是什么?是通过首选项屏幕(但如果用户错过了这个怎么办?),还是弹出一个对话框并要求用户提供凭据?如果是这样,我必须维护应用程序的状态.我该怎么做?

If I want to store the username and password to be used inside an Android application, what is the best way to do it? Is it through the preferences screen (but what if the user misses this?), or pop up a dialog box and ask the user for the credentials? If so, I do have to maintain state for the application. How would I do this?

推荐答案

我见过的大多数 Android 和 iPhone 应用程序都使用初始屏幕或对话框来询问凭据.我认为用户必须经常重新输入他们的名称/密码很麻烦,因此从可用性的角度存储这些信息是有意义的.

Most Android and iPhone apps I have seen use an initial screen or dialog box to ask for credentials. I think it is cumbersome for the user to have to re-enter their name/password often, so storing that info makes sense from a usability perspective.

来自(Android 开发指南)的建议是:

一般来说,我们建议尽量减少询问用户的频率凭据——使网络钓鱼攻击更显眼,更少可能会成功.而是使用授权令牌和刷新一下.

In general, we recommend minimizing the frequency of asking for user credentials -- to make phishing attacks more conspicuous, and less likely to be successful. Instead use an authorization token and refresh it.

在可能的情况下,用户名和密码不应存储在设备.相反,使用用户名和用户提供的密码,然后使用一个短暂的,特定于服务的授权令牌.

Where possible, username and password should not be stored on the device. Instead, perform initial authentication using the username and password supplied by the user, and then use a short-lived, service-specific authorization token.

使用 AccountManger 是存储凭据的最佳选择.SampleSyncAdapter 提供了如何使用它的示例.

Using the AccountManger is the best option for storing credentials. The SampleSyncAdapter provides an example of how to use it.

如果由于某种原因这不是您的选择,您可以使用 首选项 机制.其他应用程序将无法访问您的首选项,因此用户的信息不容易暴露.

If this is not an option to you for some reason, you can fall back to persisting credentials using the Preferences mechanism. Other applications won't be able to access your preferences, so the user's information is not easily exposed.

这篇关于Android:存储用户名和密码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆