using System;
using System.Configuration;
using System.Security.Cryptography;
using System.Text;
using System.Web;
using System.Web.Security;
namespace ScrewTurn.Wiki {
///
/// Helps computing Hash codes.
///
public static class Hash {
///
/// Computes the Hash code of a string.
///
/// The string.
/// The Hash code.
public static byte[] ComputeBytes(string input) {
MD5 md5 = MD5CryptoServiceProvider.Create();
return md5.ComputeHash(Encoding.ASCII.GetBytes(input));
}
///
/// Computes the Hash code of a string and converts it into a Hex string.
///
/// The string.
/// The Hash code, converted into a Hex string.
public static string Compute(string input) {
byte[] bytes = ComputeBytes(input);
string result = "";
for(int i = 0; i < bytes.Length; i++) {
result += string.Format("{0:X2}", bytes[i]);
}
return result;
}
///
/// Computes the Hash of a Username, mixing it with other data, in order to avoid illegal Account activations.
///
/// The Username.
/// The email.
/// The date/time.
/// The other data to mix into the input string.
/// The secured Hash of the Username.
public static string ComputeSecurityHash(string username, string email, DateTime dateTime, string otherData) {
// Use a salt (is this actually useful given that STW is opensource and everyone can see the salt?)
return Compute(otherData + username + email + dateTime.ToString("yyyyMMddHHmmss") +"$kbfl?nfc4");
}
}
}