Results 1 to 2 of 2

Thread: Binary Password Field

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2002
    Location
    Belfast, N. Ireland
    Posts
    167

    Binary Password Field

    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.
    Last edited by Justy; Feb 24th, 2004 at 12:04 PM.

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    Aug 2002
    Location
    Belfast, N. Ireland
    Posts
    167
    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:
    1. Private Function CompareByteArrays(ByVal b1 As Byte(), ByVal b2 As Byte()) As Boolean
    2.  
    3.         Dim i As Integer
    4.         Dim blnSame As Boolean = True
    5.  
    6.         Try
    7.             For i = 0 To Math.Min(b1.Length, b2.Length) - 1
    8.                 If b1(i) <> b2(i) Then
    9.                     blnSame = False
    10.                     Exit For
    11.                 End If
    12.             Next
    13.  
    14.             If b1.Length <> b2.Length Then
    15.                 blnSame = False
    16.             End If
    17.  
    18.         Catch
    19.             blnSame = False                    
    20.         End Try        
    21.  
    22.         Return blnSame
    23.  
    24.     End Function

    Thanks anyway.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width