I’m coding a website with a DB for register/login purposes.
I’ve got the setup of the DB and the connection figured out, but hashing the password is my main problem, at the moment.
For some reason, it doesn’t work and I’m out of ideas to the reason.
The code for the connection to the DB and for hashing (ignore the comments):
(I’m using PHP 8.4.7)
<?php
session_start();
require_once 'server.php'; #conectar á BD
if(isset($_POST ['criar_conta'])){ #se o botão de registar foi clicado:
$nome = $_POST['username'];
$email = $_POST['email'];
$password = password_hash($_POST['password'], PASSWORD_DEFAULT);
$verEmail = $conn->query("SELECT email FROM login WHERE email = '$email'"); #verificar se o email inserido não está na BD
if ($verEmail-> num_rows > 0) {
$_SESSION['erro_registo'] = 'Email já foi registado'; # se estiver, informa o user mas não continua o processo e nao poe na BD
$_SESSION['active_form'] = 'registo';
} else {
$conn->query("INSERT INTO login (nome, email, password) VALUES('$nome', '$email', '$password')"); #se o email nao estiver na BD, insere todos os dados fornecidos na BD
}
header("Location: pagina-login.php"); #apos isto tudo, redireciona para a pagina de login
exit();
}
?>
I think it’s also worth noting, that in VSCODE, the “PASSWORD_DEFAULT” doesn’t turn any color, its white as if its not recognized.
When I try to insert data into the DB, the webpage redirects me to this error:
“Fatal error: Call to undefined function password_hash() in
C:xampphtdocsWebsite-PAPregisto-data.php on line 9”
(Website-PAP is the name of the folder I’m using to save the project, not a library)
Any help would be appreciated.
Reinstalling PHP;
Read the password_hash manual from PHP and found nothing wrong;
No typos.