To create a hash from a string using the SHA1 algorithm in PHP, you can use the hash()
function with the "sha1" algorithm identifier. Here's an example:
main.php121 chars4 lines
In the example above, we first define a string $string
that we want to hash. We then call the hash()
function with the algorithm identifier "sha1" and pass in the string to be hashed as the second argument. The resulting hash is stored in the variable $hash
and then printed out using echo
.
It's important to note that the SHA1 algorithm is not recommended for cryptographic purposes anymore, as it's considered vulnerable to collision attacks. Instead, you should consider using one of the newer, more secure algorithms available in PHP's hash()
function, such as SHA256 or SHA512.
gistlibby LogSnag