PDA

Click to See Complete Forum and Search --> : bytes checking/comparing...


Techno
Jun 23rd, 2005, 06:37 PM
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!

MrPolite
Jun 23rd, 2005, 09:58 PM
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);

Techno
Jun 24th, 2005, 06:03 AM
no that will not work because the byte array could have a 0 in it... example:

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

:( :)

axion_sa
Jun 24th, 2005, 01:42 PM
\0 is an escape character - represents the null terminating character; it should work :)

Techno
Jun 24th, 2005, 02:32 PM
your right... hope that works ;)