gpt4 book ai didi

android - 如何处理屏幕旋转上的密码输入

转载 作者:行者123 更新时间:2023-11-29 01:14:29 25 4
gpt4 key购买 nike

在我的应用程序中,我有一个用户输入密码的 fragment 。这个 fragment 可以旋转。在旋转时,我希望使用 onSaveInstanceStateonActivityCreated 保存和恢复大部分文本字段。通常,当我将密码保存到磁盘时,我会使用单向散列来限制此信息泄露时可能造成的损害程度。但是,如果密码只写了一半,那么我就不能进行单向哈希...它需要可恢复。

所以我的问题是:将密码放在 Bundle 中安全吗?或者如果 fragment 被销毁,我应该简单地销毁该值吗?以下代码是否对我的用户构成安全风险?

public override void OnSaveInstanceState(Bundle savedInstanceState)
{
base.OnSaveInstanceState(savedInstanceState);
savedInstanceState.PutString("passEditText", _passEditText.Text);
...
}

public override void OnActivityCreated(Bundle savedInstanceState)
{
base.OnActivityCreated(savedInstanceState);
if (savedInstanceState != null)
{
_passEditText.Text = savedInstanceState.GetString("passEditText", "");
...
}
}

最佳答案

Fragments 有一个 SaveFragmentInstanceState 方法。

Save the current instance state of the given Fragment. This can be used later when creating a new instance of the Fragment and adding it to the fragment manager, to have it create itself to match the current state returned here.

引用:Xamarin:SaveFragmentInstanceState引用:安卓:saveFragmentInstanceState

安全吗?

它与内存中的任何对象一样安全,或不安全,包括其中包含部分/完整密码的 EditText。不要将包内容序列化到磁盘或使用 PersistableBundle 保存安全信息...

关于android - 如何处理屏幕旋转上的密码输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40710137/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com