Click here to Skip to main content
15,888,162 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a small app that needs user credentials to operate. Whats the best way(library) to store those credentials for later use using .NET Thanks in advance.
Posted
Updated 18-Apr-11 7:44am
v2

.NET comes with tons of Crypto APIs. Take a look here:

http://msdn.microsoft.com/en-us/library/system.security.cryptography.aspx[^]

You need to pick one based on whether you want one-way encryption, hashing, private keys, etc. Too many factors and choices there, so it's eventually up to you and based on what you need for your specific scenario.
 
Share this answer
 
v2
Comments
Tarun.K.S 18-Apr-11 14:19pm    
Good advice. 5+
Nish Nishant 18-Apr-11 18:14pm    
Thank you.
Espen Harlinn 18-Apr-11 17:39pm    
Important link, my 5
Nish Nishant 18-Apr-11 18:14pm    
Thanks!
Espen Harlinn 7-May-12 6:04am    
Good reply :-D
You should never ever store passwords in their original form. If you think about it: you never need them for authentication, as you can always compare encrypted log-in password with you stored encrypted password. With public-key cryptography, you also don't have to store a private key (which is a ciphering key in this case; knowledge of a public key helps to decipher, but not cipher).

You can also store cryptographic hash of the password.

For strong ciphering I would advice RSA, see http://en.wikipedia.org/wiki/RSA[^], use System.Security.Cryptography.RSA, System.Security.Cryptography.RSACryptoServiceProvider, see http://msdn.microsoft.com/en-us/library/system.security.cryptography.rsa.aspx[^]. You need to understand Public-key Cryptography, see http://en.wikipedia.org/wiki/Public-key_cryptography[^].

For the Cryptographic Hash approach, you need to understand how a Cryptographic Hash Function work, see http://en.wikipedia.org/wiki/Cryptographic_hash_function[^].
For a Cryptographic Hash function, you can use, for example the one from the SHA-2 family, see http://en.wikipedia.org/wiki/SHA1[^]. It is implemented in .NET, see http://msdn.microsoft.com/en-us/library/system.security.cryptography.sha1.aspx[^].

Warning: Do not use MD5! (See http://en.wikipedia.org/wiki/MD5[^].) This algorithm is considered "broken", should never be used for any security purposes.

[EDIT]
In response to last comment by OP (on "reversible", see my response comment):
Assymmetric ciphering and public-key cryptography is based on the idea of one-way function, see http://en.wikipedia.org/wiki/One-way_function[^], see also trapdoor function: http://en.wikipedia.org/wiki/Trapdoor_one-way_function[^]. Everything is based on non-reversible algorithm.

[EDIT]

Also, don't use SHA-1 for security purpose — a security flaw was found. Please see
http://en.wikipedia.org/wiki/Sha-1[^].

—SA
 
Share this answer
 
v4
Comments
Tarun.K.S 18-Apr-11 14:20pm    
Good advice. 5+
Sergey Alexandrovich Kryukov 18-Apr-11 15:45pm    
Thank you, Tarun,
--SA
apaka 18-Apr-11 14:36pm    
I'm dealing with ftp and sftp user passwords. My idea is to encrypt them and store them in isolated storage and the decrypt the on use. It's all tricky for me because the project is probably be open source so it would be better to use some third party keychain utility, but if isn't something like that possible is the a sample way to encode an later decode a password. Thanks.
OriginalGriff 18-Apr-11 15:33pm    
No, what SA is saying is: don't use encryption at all - use a hashing algorithm instead. The difference is that hashes cannot be reversed back to an enter-able password, but do not require a key which can be read: the only input is the data to hash. If you haven't got that, you cannot find out what it is! In this instance, much, much more secure than encryption / decryption.
OriginalGriff 18-Apr-11 15:31pm    
Good advice - especially about MD5!
Like Nish said, there are way too many factors, situations, and possible requirements. We have no idea of the environment you're in, how secure it has to be, or anything even remotely associated with access control. It's a decision only you can make.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 18-Apr-11 15:47pm    
This is an important note. My 5. That's why I emphasized on understanding of what encryption and hashing can deliver to the solution.
--SA
To add to what SA said: When you store a hash of a password, do not hash the raw password either: include the UserID or UserName or other unique-to-this-user information with it before you generate the hash.

Otherwise, if two users have the same password, they will have the same hash. This can be used to break into systems, by inserting your guess as to the password and comparing it to other users hash value. Since this isn't an attempt to log in with the wrong password it is difficult to spot as an intrusion attempt.

Additionally, since many users set the password to something they remember = "password" for example - a quick look at the database hashes can immediately isolate the likely targets for easy guessing.

Including the UserID with the password in the hash prevents these quite simply!
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 18-Apr-11 15:46pm    
Thank you for good and important notes and further advices. My 5.
--SA
Sergey Alexandrovich Kryukov 18-Apr-11 16:19pm    
Unfortunately, OP just asked about "reversible" password which would completely defeat the purpose of all that and would be morally unacceptable (if I understand it right), please see the last comments if you're interested. I commented and added the [EDIT]. I don't know how else to explain it...
--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