Results 1 to 5 of 5

Thread: bytes checking/comparing...

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    bytes checking/comparing...

    hi there.

    What I am doing is a bit complicated, well really simple but some aspects of it are complicated.

    I am trying to compare a password that is stored in bytes in SQL with a textual password suppled on the form, I can convert that to bytes no problem and gives me the same bytes as the bytes used to store it IN SQL.

    the thing is, if the user wants to change the password, I Wanna make sure that the current password supplied meets the same password stored in SQL then i can allow them to change the password successfully.

    Now...

    since the binary length in SQL of the password field is 50 chars long, its all mainly 0's until the 50th char has been reached (when storing in SQL and when retrieving from SQL)

    however, this will not be the case when getting the bytes from a text value/string value, even though the first 8 bytes/sections will be the same - so I cannot do a .equals or a == to compare the 2 values because they will be in different lengths.

    how can I solve this problem? any tips/ideas?

    Thanks!

  2. #2
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428

    Re: bytes checking/comparing...

    hmm I have no idea what's going on, but if I've "guessed" correctly the SQL db reserves 50 bytes for your string password, and after the end of the string all the byte values will be zeros??
    You could compare the characters one by one and stop when you hit a 0 in the sql string ha?

    or I guess you could try
    string pass = System.Text.Encoding.ASCII.GetString ( yourByteArrayHere );

    you could remove all the null terminating strings (the 0 byte values) from it:

    int pos = pass.IndexOf ("\0");
    if (pos!=-1)
    pass = pass.Remove (pos, pass.Length-pos);
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: bytes checking/comparing...

    no that will not work because the byte array could have a 0 in it... example:

    117
    110 //<< here
    69
    00
    00
    00
    00
    ..
    ..
    ..


  4. #4
    Frenzied Member axion_sa's Avatar
    Join Date
    Jan 2002
    Location
    Joburg, RSA
    Posts
    1,724

    Re: bytes checking/comparing...

    \0 is an escape character - represents the null terminating character; it should work

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: bytes checking/comparing...

    your right... hope that works

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