PHP - hash
Trieda
Metóda - hash
(PHP 5 >= 5.1.2, PHP 7, PECL hash >= 1.1)
The hash() function is used to hash a string. The hashing
process creates a fingerprint (e.g. of a password) from which we cannot get the
original value. For security reasons, the server should not know the password
while authenticating the user but only his fingerprint. When the user enters the
password, it creates his fingerprint and compares it with a fingerprint on the
server. If they are equal, the user will be logged. Typically, besides the
password itself, a so-called salt is added to the function in the form of a
constant string.
A list of algorithms:
| Algorithm | Number of characters |
| md2 | 32 |
| md4 | 32 |
| md5 | 32 |
| sha1 | 40 |
| sha256 | 64 |
| sha384 | 96 |
| sha512 | 128 |
| ripemd128 | 32 |
| ripemd160 | 40 |
| ripemd256 | 64 |
| ripemd320 | 80 |
| whirlpool | 128 |
| tiger128,3 | 32 |
| tiger160,3 | 40 |
| tiger192,3 | 48 |
| tiger128,4 | 32 |
| tiger160,4 | 40 |
| tiger192,4 | 48 |
| snefru | 64 |
| gost | 64 |
| adler32 | 8 |
| crc32 | 8 |
| crc32b | 8 |
| haval128,3 | 32 |
| haval160,3 | 40 |
| haval192,3 | 48 |
| haval224,3 | 56 |
| haval256,3 | 64 |
| haval128,4 | 32 |
| haval160,4 | 40 |
| haval192,4 | 48 |
| haval224,4 | 56 |
| haval256,4 | 64 |
| haval128,5 | 32 |
| haval160,5 | 40 |
| haval192,5 | 48 |
| haval224,5 | 56 |
| haval256,5 | 64 |
The sha algorithm is one of the best, on the other hand,
md5 and similar algorithms are now relatively dangerous.
Procedurálne
- function hash (string $algo, string $data, bool $raw_output = false) : string
Parametre
| Názov | Dátový typ | Predvolená hodnota | Popis |
|---|---|---|---|
| $algo | string | The hashing algorithm (e.g. The list of all algorithms is available below. | |
| $data | string | A value to be hashed. | |
| $raw_output | bool | false | The last optional parameter is to switch binary data (TRUE) and hexadecimal data (FALSE, default). |
Mávratovej hodnoty
Vracia: string
The hash of the string.
Príklady
<?php
echo hash('sha512', 'my secret password' . 'my_salt');
Súvisiace manuály
- function sha1 (string $str, bool $raw_output = false) : string
