Password_Bcrypt - PHP

0

I have a shell script that randomly generates a password and saves it in pass.txt.

In php I have the code below, which opens this pass.txt, takes the password that is in it and generates the Hash overwriting the pass.txt. With this hash I saved in the mysql database:

    <?php
$senha1 = file_get_contents("/tmp/pass.txt");
#$senha1 = trim($senha1);
$senha1 = preg_replace('/s(?=s)/', '', $senha1);
$senha1 = preg_replace('/[nrt]/', ' ', $senha1);
$senha1 = preg_replace('/\s\s+/', ' ', $senha1);
$senha1 = password_hash($senha1, PASSWORD_BCRYPT, [cost => 12]);
$arquivo = "/tmp/pass.txt";
$fp = fopen($arquivo, "r+");
fwrite($fp, $senha1);
fclose($fp);
?>

However, this process is all automated and sometimes the system logs in and sometimes not. I did the manual process and at this time no access is allowed with the user and password that is generated. I do not know if in this process, when generating Hash, some garbage is being inserted and so on. But I used replace to test remove waste.

The only "strange" situation is that it generates this Warning when php is executed:

PHP Warning:  Use of undefined constant cost - assumed 'cost' (this will 
throw an Error in a future version of PHP)

I use the password_verify function to validate the password.

Through some tests, setting the password in a variable in PHP itself and generating the Hash through this variable works. But if the password is in a TXT and I get the information that is in this TXT and I encrypt the password, it does not work.

    
asked by anonymous 27.09.2018 / 23:45

0 answers