There are a lot of passwords in my head from numerous sites of which I am a member. I try not to use the same password for any two sites because very often the password I supply is stored in plain text and is therefore available to anyone who can access the sites database. Developers should never allow this to happen, and no one, but you, should ever know your password. As a rule of thumb, if you can request an e-mail which contains your password then it is likely to be stored without encryption or the wrong type.
The best way to store a password is as a Hash, this is a one way cryptographic function that will always give the same result for the same input, so to check a password is valid you simply Hash the input and compare it to the stored value. This means that only the user entering the password will know what it is, the storage will only contain the Hash. This is the way Windows stores passwords.
This is a trivial task, all you need is in the framework and with a simple extension added to the string object, hashing is as easy as falling off a log.
public static class StringExtensions {
/// <summary>
/// <para>Hash a value</para>
/// </summary>
public static string Hash(this string value) {
return value.Hash(false);
}
/// <summary>
/// <para>Hash a value</para>
/// </summary>
public static string Hash(this string value, bool base64Encode) {
var service = new MD5CryptoServiceProvider();
var bytes = service.ComputeHash(Encoding.Default.GetBytes(value));
return base64Encode
? Convert.ToBase64String(bytes)
: Encoding.Default.GetString(bytes);
}
}
A Base64 encoded string will play nice with all databases and xml, so this function contains the option to use it.
var hash = "Test".Hash(true); // Get a Base64 Hash
So what happens when your user forgets their password?
Well there are a few golden rules for this too, given the assumption that the users e-mail is secure enough;
Hashing is not enough you must add salt
http://www.antix.co.uk/A-Developers-Blog/Season-Your-Hash-Adding-Salt
| < | May 2012 | |||||
|---|---|---|---|---|---|---|
| S | M | T | W | T | F | S |
| 29 | 30 | 1 | 2 | 3 | 4 | 5 |
| 6 | 7 | 8 | 9 | 10 | 11 | 12 |
| 13 | 14 | 15 | 16 | 17 | 18 | 19 |
| 20 | 21 | 22 | 23 | 24 | 25 | 26 |
| 27 | 28 | 29 | 30 | 31 | 1 | 2 |
Add-ins AJAX ASP.NET MVC Browsers C# Caching CodeDom Compression CORS CSS CV Data Database DependencyResolver Development Dynamic Entity Framework Error Handling Extend File Upload Forms GDI+ HTML HTML Editor HTTP Interfaces JavaScript JQuery MCE MetadataProvider MSBuild Numbers Objects Patterns Progressive Enhancement Projects Publish Regex Resources Security SEO SMTP Source Control Strings Sub-Collections TDD Templates Tools Twitter User Interface WCF Web Development WHS WMC XLinq XML
1 hours ago
TheNextWeb
Bing's search API now live on the Windows Azure Marketplace http://t.co/utX8uOuG by @alex
15/05/2012
WindowsAzure
Announcing the MEET Windows Azure Event! Streamed online June 7th. Register at http://t.co/bObzTAuL #MEETAzure #WindowsAzure
One hour ago
commadelimited
Buy the @amazon Kindle version of mine and @cfjedimaster's @jquerymobile book for $10 today: http://t.co/PWRZ2dkd
just now
CSSDropDownMenu
Simple horizontal css drop down menu demo Windows Azure and Cloud Computing Posts for 4/16/2011+ This makes fo... http://t.co/DZdNLHxF
just now
WAPForums
UpdateMessage() method not available in SDK 1.6? http://t.co/fyORSB1T Windows #Azure