• Code
  • Tags
  • Users
  • Titles
  • Log in
  • Feedback
  • FAQ
Share Code
Welcome to ForkCan.com

ForkCan is all about sharing code in a social way.

Discuss, debate or argue with other devs about their or your own code.

Give other devs feedback or make a Fork (Make a better version of a shared code).

Rate the code, if you use the code mark it as used so others can see if the shared code is used by someone.

Help each other to be better devs and to be more productive.


Features not working yet:

Flag a post


QR Code

Tiny Url

http://4kcan.com/s/MjQ5

Related Code
Generic Entity Framework 4.0 Base Repository
ForEach Extension method for IEnumerable<T>
To, FromBase64 and ToHash (Flash code friendly) Extension
Invoke Extension Method
Use of Extension methods to hide "infrastructure code"
Unity Service Locator for ASP.NET MVC 3.0 Beta 1
Null Dot "Operator" Extension Method
Generic Entity Framework 4.0 Base Repository with Paging
Generic linq-to-sql repository
WCF RIA Services Unity 2.0 DomainService Factory
A Default Entity Framework 4.0 ObjectContext Factory
UnitOfWork Action filter for ASP.NET MVC and nHibernate
Make sure the web.config pages/namespace can be used together with ASP.NET MVC 3 P1 and Razor
Custom C# exception class
Email validation with Regular Expression
Reflection dynamically get private fields or properties
Url Validation with Regular Expression
Number of sealed / unsealed types in the framework
Extension to the HttpClient

Method to hash passwords


0
435 0 0 1 0 2

I am going to use this newly created method to hash users password. Feel free to give me feedback!

    public static byte[] Hash(string strClear, byte[] bytUserSalt, byte[] bytSystemSalt)
    {
        UTF8Encoding utf8Encoding = new UTF8Encoding();
        SHA512Managed sha = new SHA512Managed();
        byte[] bytClearString = utf8Encoding.GetBytes(strClear);

        byte[] bytHashedUserSaltAndPassword = sha.ComputeHash(bytClearString.Concat(bytUserSalt).ToArray<byte>());
        byte[] bytHashedComplete = sha.ComputeHash(bytHashedUserSaltAndPassword.Concat(bytSystemSalt).ToArray<byte>());

        return bytHashedComplete;
    }

Share: twitter | facebook   Action: used | fork | flag

.net

Mark '.net' tag as 'like'

Mark '.net' tag as 'ignore'

c#

Mark 'c#' tag as 'like'

Mark 'c#' tag as 'ignore'

hash

Mark 'hash' tag as 'like'

Mark 'hash' tag as 'ignore'


 Jiggr "Code Contributor"
123
September 15, 2010 8:28 PM
edited September 15, 2010 10:05 PM

Fork

 Method to hash passwords - Jiggr Wednesday 15, 2010 8:28 PM


1 Feedback

What's wrong with the FormsAuthentication.HashPasswordForStoringInConfigFile Method? If anything the name is awesome. -  @davidbbitton Wednesday 15, 2010 10:30 PM

You must log in before you can give any feedback


2 Discussion(s)

Newest Oldest
0

This might be be a little cleaner, and you can inject it as a dependancy (stolen from CodeCampServer):

public interface ICryptographer
{
	string CreateSalt();
	string ComputeHash(string valueToHash);
	string GetPasswordHash(string password, string salt);
}

public class Cryptographer : ICryptographer
{
	/// <summary>
	/// Create salt for encrypting user passwords.  
	/// Original Source: http://davidhayden.com/blog/dave/archive/2004/02/16/157.aspx
	/// </summary>
	/// <returns></returns>
	public string CreateSalt()
	{
		int size = 64;
		//Generate a cryptographic random number.
		var rng = new RNGCryptoServiceProvider();
		var buff = new byte[size];
		rng.GetBytes(buff);

		// Return a Base64 string representation of the random number.
		return Convert.ToBase64String(buff);
	}

	/// <summary>
	/// Create a password hash based on a password and salt.  
	/// Adapted from: http://davidhayden.com/blog/dave/archive/2004/02/16/157.aspx
	/// </summary>
	/// <returns></returns>
	public string ComputeHash(string valueToHash)
	{
		HashAlgorithm algorithm = SHA512.Create();
		byte[] hash = algorithm.ComputeHash(Encoding.UTF8.GetBytes(valueToHash));

		return Convert.ToBase64String(hash);
	}

	public string GetPasswordHash(string password, string salt)
	{
		return ComputeHash(password + salt);
	}
}
link | flag  | Reply

 cstrahan
12
Thursday 16, 2010 8:37 PM

0

Reply to: cstrahan

Maybe the Fork feature is little invisible, but by pressing the Fork link, you can make a fork of the original code and share a new version that you think is better. Only want to remind people about this feature ;)

link | flag  | Reply

 @fredrikn "I'm the master"
3.11k
Thursday 16, 2010 9:33 PM


You must log in before you can post a comment

Squeed
Made by: Fredrik Normén 2010