password_verify

(PHP 5 >= 5.5.0)

password_verifyVerifies that a password matches a hash

Описание

boolean password_verify ( string $password , string $hash )

Verifies that the given hash matches the given password.

Note that password_hash() returns the algorithm, cost and salt as part of the returned hash. Therefore, all information that's needed to verify the hash is included in it. This allows the verify function to verify the hash without needing separate storage for the salt or algorithm information.

Список параметров

password

Пользовательский пароль.

hash

Хэш, созданный функцией password_hash().

Возвращаемые значения

Returns TRUE if the password and hash match, or FALSE otherwise.

Примеры

Пример #1 password_verify() example

<?php
// See the password_hash() example to see where this came from.
$hash '$2y$07$BCryptRequires22Chrcte/VlQH0piJtjXl.0t1XkA8pw9dMXTpOq';

if (
password_verify('rasmuslerdorf'$hash)) {
    echo 
'Password is valid!';
} else {
    echo 
'Invalid password.';
}
?>

Результат выполнения данного примера:

Password is valid!

Смотрите также

Коментарии

Автор:
Imagine you are using an API between servers (where the password is stored in the API server) and you want to avoid passing the password in plain text via the API, or sending the full hash to the API client.

You can just receive the original salt and re-crypt the password on the API client, then you can send the recrypted password to the API server to compare them.

<?php

define
('BLOWFISH_SALT_LENGTH'23);
$pass 'maduranma';

$original password_hash($passPASSWORD_DEFAULT); // Equivalent to PASSWORD_BCRYPT

$salt substr($original0strrpos($original'$') + BLOWFISH_SALT_LENGTH);

$recrypted crypt($pass$salt); // This can be done on the API client and sent to the API server

// So we can compare both:
var_dump($original === $recrypted); // Returns true, should be done on the API server
2023-12-13 17:03:58
http://php5.kiev.ua/manual/ru/function.password-verify.html
Автор:
Imagine you are using an API between servers (where the password is stored in the API server) and you want to avoid passing the password in plain text via the API, or sending the full hash to the API client.

You can just receive the original salt and re-crypt the password on the API client, then you can send the recrypted password to the API server to compare them.

<?php

define
('BLOWFISH_SALT_LENGTH'23);
$pass 'maduranma';

$original password_hash($passPASSWORD_DEFAULT); // Equivalent to PASSWORD_BCRYPT

$salt substr($original0strrpos($original'$') + BLOWFISH_SALT_LENGTH);

$recrypted crypt($pass$salt); // This can be done on the API client and sent to the API server

// So we can compare both:
var_dump($original === $recrypted); // Returns true, should be done on the API server
2023-12-13 17:03:58
http://php5.kiev.ua/manual/ru/function.password-verify.html

    Поддержать сайт на родительском проекте КГБ