0
Goodnight!
I use the PASSWORD_BCRYPT function to encrypt my passwords. When I use the code below:
//conteudo do pass.txt é: yW9ujS
$arquivo = fopen('/tmp/pass.txt','r+');
$linha = fgets($arquivo);
$senha = password_hash($linha, PASSWORD_BCRYPT, [cost => 12]);
echo "$senha";
Generates a hash as expected. Saved this Hash in the database and when I try to access in my application with the user and password (yW9ujS) it says that the password is invalid.
In case I use the command below:
//conteudo do pass.txt é: yW9ujS
$arquivo = "yW9ujS";
$senha = password_hash($arquivo, PASSWORD_BCRYPT, [cost => 12]);
echo "$senha";
A hash is generated and when I save this new hash in the database, I do an access test on the application, and the access happens.
It seems that when I use fopen, some "Trash" is added during the process and PASWORD_BCRYPT ends up encrypting everything together and the hash ends up changing.
If I just send an echo in $line, it appears exactly the password that is in the pass.txt file
$linha = fgets($arquivo);
One wonders what it can be?
It wasn’t easier to use
file_get_contents
?– Wallace Maxters
Yes, I used this function too :
$linhas = file_get_contents("/tmp/pass.txt");
$senha = password_hash($linhas, PASSWORD_BCRYPT, [cost => 12]);
echo $senha
, it generates a hash and I set this hash in the non-log bank. If I set a variable with the same password and call the function above, it generates a new hash, Seto in the database and log.– user54154
He returns like this
$2y$12$oFYcRX2SKgg3b5rn0lNylu0WtUCo58tWNm66jmtcIKwQ8AdAQiW4y[root@ scripts]#
while setting the password manually returns like this$2y$12$.4x5s/pWzNXjlvXLlDvNH.gkHjgH0B5Bvct2FABcTFCHGBY5EKPsW
., I believe that this return with root... is generating the problem.– user54154
Dear, really the problem was some junk in the process, I used the functions
trim, preg_replace('/s(?=s)/', '' , preg_replace('/[nrt]/', ' '
and it worked.– user54154