static public class HashFunctions >> { >> public static Byte[] GetHashValue(string s) >> { >> byte[] source = ASCIIEncoding.ASCII.GetBytes(s); >> return new MD5CryptoServiceProvider().ComputeHash(source); >> } >> >> public static bool CompareHash(byte[] first, byte[] second) >> { >> bool equal = false; >> if (first.Length == second.Length) >> { >> int i=0; >> while (i < first.Length && (first[i] == second[i])) >> i++; >> equal = i == first.Length; >> } >> return equal; >> } >> >> public static bool CompareHash(byte[] b,string s) >> { >> return CompareHash(b, GetHashValue(s)); >> } >> }The password is stored as a byte array (varbinary() in MSSQL)
>namespace GregoryAdam.Base.ExtensionMethods >{ > public static partial class ExtensionMethods_Array > { > //______________________________________________________________________ > /// <summary> > /// returns whether the contents of a range are equal to another range > /// </summary> > /// <typeparam name="T"></typeparam> > /// <param name="thisArray"></param> > /// <param name="thisIndex"></param> > /// <param name="otherArray"></param> > /// <param name="otherIndex"></param> > /// <param name="length"></param> > /// <returns></returns> > public static bool ContentsEqual<T>(this T[] thisArray, int thisIndex, T[] otherArray, int otherIndex, int length) > where T : IEquatable<T> > { > if ( otherArray == null ) > return false; > > for (; --length >= 0; ) > if (!thisArray[thisIndex++].Equals(otherArray[otherIndex++])) > return false; > > return true; > } > //______________________________________________________________________ > public static bool ContentsEqual<T>( this T[] array, int index1, int index2, int length ) > where T : IEquatable<T> > { > return array.ContentsEqual(index1, array, index2, length); > } > //______________________________________________________________________ > public static bool ContentsEqual<T>( this T[] array, T[] otherArray ) > where T : IEquatable<T> > { > if ( otherArray == null ) > return false; > > if ( array.Length != otherArray.Length ) > return false; > > return array.ContentsEqual(array.GetLowerBound(0), otherArray, otherArray.GetLowerBound(0), array.Length); > } > //______________________________________________________________________ > } >} >Thanks! In this instance I probably won't use it since I don't need the flexibility of specifying a range - but it will be useful elsewhere.
for (; --length >= 0; ) > if (!thisArray[thisIndex++].Equals(otherArray[otherIndex++])) > return false;or my:
while (i < first.Length && (first[i] == second[i]))
i++;
equal = i == first.Length;