Click here to Skip to main content
15,883,883 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
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.
Posted
Comments
Sergey Alexandrovich Kryukov 11-Jan-15 12:15pm    
Your language?
—SA
Salah Abualrob 13-Jan-15 6:56am    
i am using java
Sergey Alexandrovich Kryukov 13-Jan-15 11:03am    
This is what I assumed in my answer.
—SA

1 solution

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
 
Share this answer
 
Comments
Salah Abualrob 13-Jan-15 7:00am    
thanks for rich information that i dont know and i will implement,
but my question was .. is there anywhere to store the hash other saving it in table in the database?
Sergey Alexandrovich Kryukov 13-Jan-15 11:02am    
Good. You can store password hash data in any safe location where it cannot be replaced or removed, even in files. Most important thing is that a person who can even read this data cannot figure out original password.
Will you accept this answer formally now? In all cases, your follow-up questions will be welcome.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900