Susan Platz
Susan Platz

Reputation: 7

Hash in Laravel

there. I'm preparing a Laravel test, and there's a question that I think is not correct. When you should use a hash? The available answers are:

Since hashing is for encrypting passwords (not to send'em over email) none of this answers seem to be correct. What do you think?

Upvotes: 0

Views: 329

Answers (1)

K4jt3c
K4jt3c

Reputation: 151

Option 4. Identifying contents of a file.

Hash is a function which is supposed to return a constant length output for every input. The other property of hash functions is that for any input a it always returns the same value b. It means that if you provide file a and store its hash b then whenever you supply file a again you're going to get hash b. The last property is that for different inputs c, d and hash function f, f(c) should be different from f(d) (or the chances of outputs being equal should be near 0)

In real case scenario, you can often find hashes when downloading software and want to verify if the file you've downloaded is correct. The developer puts a hash of the executable on their site. You are downloading the file and calculate checksum (hash) just to compare it with the one from the website. If it matches, then you know it's the same (as long as the hash algorithm is not known to have collisions...).

It is quite good approach to comparing file contents, bc hashes are taking much less space than actual files.

Upvotes: 1

Related Questions