How should I compare a binary password field in an SQL Server database with a string in my .NET application?
System.Text.Encoding.ASCII.GetBytes ?
A sample code snippet would be dead handy... Thanks!
Justin.
Printable View
How should I compare a binary password field in an SQL Server database with a string in my .NET application?
System.Text.Encoding.ASCII.GetBytes ?
A sample code snippet would be dead handy... Thanks!
Justin.
Well anyway, for anyone else, you have to convert the string to a byte array and compare each byte with each byte of the binary field using code something like...
VB Code:
Private Function CompareByteArrays(ByVal b1 As Byte(), ByVal b2 As Byte()) As Boolean Dim i As Integer Dim blnSame As Boolean = True Try For i = 0 To Math.Min(b1.Length, b2.Length) - 1 If b1(i) <> b2(i) Then blnSame = False Exit For End If Next If b1.Length <> b2.Length Then blnSame = False End If Catch blnSame = False End Try Return blnSame End Function
Thanks anyway.