The php Function Hash_File
The php function hash_file can be used to calculate the MD5 hash of a file. MD5 is a cryptographic hash algorithm that creates a 128-bit "fingerprint" of an input message that can be used to verify data integrity and authenticity.
The hash_file() function takes three parameters: $algo, $file and $raw_opt. The algo parameter specifies which hashing algorithm is to be used. There are many to choose from including md5, sha256, and more. The file parameter specifies the path to the file whose contents should be hashed. The raw_opt parameter allows you to select whether the resulting hash should be returned as a string of lowercase hexadecimal characters or as a raw binary data.
In the past, the use of hashing algorithms like md5 became popular for checking file integrity when downloading from web sites. This is because when a file is downloaded, its hash value is attached to the download so that anyone who checks it can see that the downloaded version matches the original checksum.
It is also common to use SHA1 when uploading files to a website. This is because SHA1 provides more security than md5. This is because it provides the ability to identify if an uploaded file has been modified since it was created on the server.
The bcrypt hashing algorithm is also commonly used with PHP and MySQL, and the password_hash() and password_verify() functions are a good choice for storing and comparing encrypted passwords in databases. Among its advantages, bcrypt is slow to hash which makes it difficult for attackers to generate rainbow tables and crack passwords in a reasonable amount of time. It also incorporates a salt value for each password to prevent hash collisions.