How would I check whether those 2 pieces are identical?
Convert each character to a number. Subtract each number from the number of its corresponding character. If the result is ever not zero they ain’t equal. Works when the lengths are the same. Hint, if the length isn’t the same they ain’t equal. It’s called string comparison.
If I decided to use a hash to compare them, it wouldn't be reliable because a tiny difference, such as a whitespace or anything else would result in a different hash.
That’s not the problem with a hash. The problem with a hash is collisions that say they’re equal when they’re not. No matter how good the hash algorithm the pigeonhole principle says you can’t reduce the bits of an arbitrary length string to a fixed size integer without collisions. The best you can do is make them unlikely. If you can accept that risk then a hash is fine for this.
The advantage of a hash is that you won't have to store the old string in the DB. Just the hash.
But you have exactly the same "reliable" problem either way you do it. Both hash and string comparison require you to prep the string before hand. If that means trimming whitespace or making everything lower case or whatever "anything else" means, you have to do it before the hashing algorithm see's what you want to ignore.