라이브러리

[PHP] sodium_crypto_pwhash_str_verify - 비밀번호가 해시와 일치하는지 확인합니다.




PHP에서 Password Hashing

PHP에서 password hashing은 보안을 위해 매우 중요합니다. PHP 7.2부터는 `password_hash()` 함수를 사용하여 password hashing을 할 수 있습니다. 하지만, PHP 7.2 이전 버전에서는 `password_hash()` 함수가 지원되지 않습니다. 이 경우, `sodium_crypto_pwhash_str_verify` 함수를 사용하여 password hashing을 할 수 있습니다.

sodium_crypto_pwhash_str_verify 함수


`sodium_crypto_pwhash_str_verify` 함수는 password hashing을 위해 사용되는 함수입니다. 이 함수는 password hashing을 위해 사용되는 salt와 password를 비교합니다.

# 함수의 매개변수


`sodium_crypto_pwhash_str_verify` 함수의 매개변수는 다음과 같습니다.

* `$password`: password hashing을 위해 사용되는 password
* `$hash`: password hashing을 위해 사용되는 salt

# 함수의 반환값


`sodium_crypto_pwhash_str_verify` 함수의 반환값은 boolean 값입니다. password hashing을 위해 사용되는 password와 salt가 일치하면 true를 반환하고, 일치하지 않으면 false를 반환합니다.

예제


다음 예제는 `sodium_crypto_pwhash_str_verify` 함수를 사용하여 password hashing을 하는 방법을 보여줍니다.

#hostingforum.kr
php

<?php



// password hashing을 위해 사용되는 password

$password = "mysecretpassword";



// password hashing을 위해 사용되는 salt

$salt = sodium_crypto_pwhash_str_random(16);



// password hashing을 위해 사용되는 password와 salt를 사용하여 password hashing을 합니다.

$hash = sodium_crypto_pwhash_str($password, $salt);



// password hashing을 위해 사용되는 password와 salt를 비교합니다.

if (sodium_crypto_pwhash_str_verify($hash, $password)) {

    echo "Password is correct";

} else {

    echo "Password is incorrect";

}



?>



참고


`sodium_crypto_pwhash_str_verify` 함수는 PHP 7.2 이전 버전에서만 사용할 수 있습니다. PHP 7.2 이상 버전에서는 `password_hash()` 함수를 사용하여 password hashing을 할 수 있습니다.

#hostingforum.kr
php

<?php



// password hashing을 위해 사용되는 password

$password = "mysecretpassword";



// password hashing을 위해 사용되는 salt

$salt = random_bytes(16);



// password hashing을 위해 사용되는 password와 salt를 사용하여 password hashing을 합니다.

$hash = password_hash($password, PASSWORD_BCRYPT, ['salt' => $salt]);



// password hashing을 위해 사용되는 password와 salt를 비교합니다.

if (password_verify($password, $hash)) {

    echo "Password is correct";

} else {

    echo "Password is incorrect";

}



?>



결론


`sodium_crypto_pwhash_str_verify` 함수는 password hashing을 위해 사용되는 password와 salt를 비교하는 함수입니다. 이 함수는 PHP 7.2 이전 버전에서만 사용할 수 있습니다. PHP 7.2 이상 버전에서는 `password_hash()` 함수를 사용하여 password hashing을 할 수 있습니다.
  • profile_image
    나우호스팅 @pcs8404 

    호스팅포럼 화이팅!

    댓글목록

    등록된 댓글이 없습니다.

  • 전체 8,985건 / 174 페이지

검색

게시물 검색