如何使用密码保护我的Android应用程序? [英] How Do I Protect My Android App With Password?

查看:67
本文介绍了如何使用密码保护我的Android应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我正在开发一个Android应用程序,我需要问用户输入密码,保存用户名和密码的最佳方法是什么?

无论如何要保存它而不使用sqlite ?我不想创建一个表只是为了保存一个用户名和密码,任何人都有一个想法?

提前感谢。

hi all, i am developing an application in android and i need to ask user for password, what is the best way to save username and password?
is there anyway to save it without using sqlite? i don't want to create a table just to save one username and pasword, anyone have an idea?
thanks in advance.

推荐答案

您甚至没有指定您正在使用的语言。我假设您使用的是Java。这很好,因为解决方案的想法对于任何其他语言都是一样的。



首先,你永远不应该把密码存储在任何地方:这是不安全的绝对不需要身份验证。 (惊讶?不同意?继续阅读...)首先,没有人应该知道原始密码,即使是完全访问密码存储的人;只有最初创建密码的人应该能够知道它;密码对其用户有一个单独的值,超出了对某个实体的保护。



这就是这个问题的解决方法:你计算加密哈希函数密码和仅存储哈希,仅比较哈希与哈希。此功能使加密不可行恢复原始密码(请记住,这不是加密)。请参阅:

http://en.wikipedia.org/wiki/Cryptographic_hash_function [< a href =http://en.wikipedia.org/wiki/Cryptographic_hash_functiontarget =_ blanktitle =New Window> ^ ]。



您可以使用 Java.java.security.MessageDigest

http://docs.oracle.com/javase/7/docs/api/java/security/MessageDigest.html [ ^ ]。



更好地使用SHA-256,这是SHA-2系列的算法之一,而不是SHA-1,它被发现被破坏了。请参阅:

http://en.wikipedia.org/wiki/SHA-2 [ ^ ],

http://en.wikipedia.org/wiki/SHA-1 [ ^ ]。



请不要以为我只需要简单的保护。这个解决方案已经很简单;它被普遍接受。如果你存储密码,你不仅可以打破一个特定的应用程序,这没关系。您可能会泄露某些人的密码,这是不可接受的。



-SA
You did not even specify the language you are using. I'll assume you are using Java. It's fine, because the idea of the solution will be the same for any other language.

First of all, you should never ever store passwords anywhere: this is unsafe and absolutely not needed for authentication. (Surprised? Disagree? Keep reading…) First of all, no one should know original passwords, even the person who has the full access to the password storage; only the person who initially created a password should be able to know it; a password has a separate value for its user, beyond its protection of certain entity.

This is how this problem is solved: you calculate the cryptographic hash function of passwords and store only hash, compare only hash with hash. This function makes it cryptographically infeasible to restore original password (remember, this is not encryption). Please see:
http://en.wikipedia.org/wiki/Cryptographic_hash_function[^].

You can use Java.java.security.MessageDigest:
http://docs.oracle.com/javase/7/docs/api/java/security/MessageDigest.html[^].

Better use SHA-256, one of the algorithms from SHA-2 family, and not SHA-1, which was found broken. Please see:
http://en.wikipedia.org/wiki/SHA-2[^],
http://en.wikipedia.org/wiki/SHA-1[^].

Please don't think "I only need simple protection". This solution is already simple; and it is commonly accepted. If you store passwords, you don't just allow to break one particular application, which would be fine. You would potentially disclose some people's passwords, that would be unacceptable.

—SA


这篇关于如何使用密码保护我的Android应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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