Comparing Strings with different hex values

Hi there,

I need to compare two strings. One of them gets selected out of MySQL and the other one is provided through a textField from the User.
Both strings look like the same but my boolean property won’t turn true, so I converted them to their hex values and one of them has exactly one different byte/character.

How can I prevent this and what could call this issue?

Have you tried making sure the string encoding is exactly the same?

Where can I see the text encoding or how can I proof if it is the same? I already read about some similiar problem like mine but I couldn’t come up with a solution.

try something like:

Var result1 As String
result1 = TextField1.Value.ConvertEncoding(Encodings.UTF8) // use whaterver encoding is best for your project

Var result2 As String
result2 = TextField2.Value.ConvertEncoding(Encodings.UTF8) // use whaterver encoding is best for your project

// use your comparison code on result1 & result2

Unfortunately it still doesn’t work.
If it helps both strings are hashes generated with following code:

Var hashValue As String
VAR kSalt AS STRING = “RUEDEjeje#@fj(*”
VAR value AS STRING = Loginpage.Password.Text

hashValue = Crypto.PBKDF2(kSalt, value, 128, 32, Crypto.HashAlgorithms.SHA512)

Return hashValue

Is the string the actual hash value? If so, that’s binary and you should store and retrieve it as hex (or Base64) instead of the raw bytes.

Otherwise, what specifically is the difference?

Are you making sure the encoding is the same BEFORE processing the hash?

Yes the String is the actual hash value. So you mean before I store the hash value in the string I should convert it to hex and then store it?

Yes.

Thank you very much now it works!!!

1 Like

Glad to hear it.

Please remember to mark a “solution” here.