Created
July 6, 2015 13:00
-
-
Save nevadascout/6bc2aacfa149637cff8c to your computer and use it in GitHub Desktop.
Gravatar MD5 Hash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static MvcHtmlString GetGravatarForUser(string email, int size = 50) | |
{ | |
var hash = Md5.CreateHash(email); | |
// return new MvcHtmlString(string.Format("https://secure.gravatar.com/avatar/{0}?s=50&d={1}", hash, defaultAvatarUrl)); | |
return new MvcHtmlString(string.Format("https://secure.gravatar.com/avatar/{0}?s={1}", hash, size)); | |
} | |
public class Md5 | |
{ | |
/// <summary> | |
/// Create an MD5 hash for a given string | |
/// </summary> | |
/// <param name="input"> | |
/// The input string | |
/// </param> | |
/// <returns> | |
/// The computed hash | |
/// </returns> | |
public static string CreateHash(string input) | |
{ | |
input = input.ToLower(); | |
var encodedInput = new UTF8Encoding().GetBytes(input); | |
var hash = ((HashAlgorithm)CryptoConfig.CreateFromName("MD5")).ComputeHash(encodedInput); | |
var encoded = BitConverter.ToString(hash).Replace("-", string.Empty).ToLower(); | |
return encoded; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment