Logo

1.9K views Asked 18 Dec 2021 in PHP
3

I am creating a signup form using PHP and MYSQL database. I am getting an error Uncaught TypeError: password_hash(): Argument #3 ($options) must be of type array, null given in C:\xampp\htdocs\form\signup.php:104 Stack trace: #0 C:\xampp\htdocs\form\signup.php(104): password_hash('hello123', '2y', NULL) #1 {main} thrown in PHP. I want to convert simple text to hash pattern using password_hash() function but getting TypeError: password_hash(): Argument #3 ($options) must be of type array, null given error .

I tried PHP code - 

<?php 
password_hash('hello123', '2y', NULL)
?>

Is there any solution to fix it? 

User arnabisaha (2.5K Points)

edited 18 Dec 2021

2 Answers
2
vishalrana (3.6K Points)

answered 18 Dec 2021 (edited)

According to this error Uncaught TypeError: password_hash(): Argument #3 ($options) must be of type array, null given you passed third parameter null. This error comes when you pass the third parameter null. According to this error, you cannot pass the third optional parameter as null value. Focus on your error Argument #3 ($options) must be of type array. It's saying the third parameter should be an array type.

$password='admin@123';
    $options = array("cost"=>4);
    $password = password_hash($password,PASSWORD_BCRYPT,$options);

In the solution above I created an array type and pass in the third parameter. You can check reference here - 

Registration and login form in PHP and MYSQL


The error has been removed. Thank you for your help.  –  arnabisaha 18 Dec 2021
Add comment

2
shakti (9.6K Points)

answered 18 Dec 2021 (edited)

The third parameter should be an array type in the password_has() function.
You are passing the Null value in the third parameter. Change it like this -

This is totally wrong way to convert simple text to the hash pattern in PHP -

password_hash('hello123', '2y', NULL)

Change above code like this - 
 

$arr = array("cost"=>4);
password_hash('hello123','PASSWORD_BCRYPT',$arr)


This is the solution of your error Uncaught TypeError: password_hash(): Argument #3 ($options) must be of type array, null given . 


Your Answer
×
Login Required

You must login to continue.

Login Login with Google
Register