Haroldo
Haroldo

Reputation: 37377

Will PHP's sha1() and MySQL's SHA() give the same result?

If no salt is used, will they be the same?

Upvotes: 9

Views: 4174

Answers (4)

Volmarg Reiso
Volmarg Reiso

Reputation: 483

Yes.

If You will run into case where these are not equal (like i just now had) then most likely You either got something wrong with Your method which uses the hash or incorrect database state where You for example updated few fields but forgot to change the corresponding hash.

Upvotes: 0

Quassnoi
Quassnoi

Reputation: 425431

Of course.

Note that the algorithm defines 160 bits and the script language implementations can return their hexadecimal representation as a string instead. The register and the dashes of the hexadecimal representation may be different in some implementations.

However, MySQL and PHP both return in lower case and no dashes.

Upvotes: 2

Mark Wilkins
Mark Wilkins

Reputation: 41222

Both claim to implement RFC 3174. Thus, they produce the same result (otherwise there is a bug in the implementation).

Upvotes: 2

Wooble
Wooble

Reputation: 89927

Yes. The sha1 algorithm always produces the same value for the same input; that's the whole point of a hashing algorithm. They also both return a 40-character lowercase hex dump by default.

Upvotes: 8

Related Questions