简体   繁体   English

密码保护Android中的偏好设置

[英]Password protect a preference in Android

Is it possible to password-protect some of the preferences? 可以用密码保护某些首选项吗?

More info: I have a user password preference (EditTextPreference), using this preference the user can change his/her password. 更多信息:我有一个用户密码首选项(EditTextPreference),使用此首选项,用户可以更改其密码。 To make it more secure one should protect such a preference with the user password. 为了使其更安全,应使用用户密码保护这种首选项。 Is that possible using preference fragment in android? 在Android中使用首选项片段是否可能?

You could encrypt the password using one of the built-in ciphers (javax.crypto) then encode the result in something like base64 (android.util.base64) which you can then store in the preferences as a string. 您可以使用内置密码(javax.crypto)之一对密码进行加密,然后将结果编码为诸如base64(android.util.base64)之类的内容,然后将其作为字符串存储在首选项中。 It is probably better to never store the password if possible. 如果可能的话,最好不要存储密码。 Perhaps use a strong non-reversible hash code (again you can probably use javax.crypto) and store the hashcode. 也许使用强大的不可逆哈希码(再次可以使用javax.crypto)并存储哈希码。 When the user enters the password, you hash it and compare against the stored hashcode. 当用户输入密码时,您对它进行哈希处理并与存储的哈希码进行比较。 If someone gets the hashcode out of the shared prefs, it is quite difficult to obtain the original password from it, and if the hashcode is strong enough it may be non-trivial to come up with a password that produces the same hash. 如果有人从共享首选项中获取哈希码,则很难从中获取原始密码,并且如果哈希码足够强大,那么想出一个产生相同哈希值的密码可能并不容易。

In reality, if someone gets hold of your application, there is always a weakness if someone really wants to get in. As my father used to say .. "Locks keep honest people out" 实际上,如果有人掌握了您的应用程序,那么如果有人真的想进入您的应用程序,则总是存在缺陷。正如我父亲曾经说过的那样: “锁使诚实的人无法进入”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM