How can user authentication via email addresses be implemented securely in PHP applications?

User authentication via email addresses can be implemented securely in PHP applications by using a combination of email verification upon registration and password hashing for secure storage. When a user registers with their email address, a verification email should be sent to confirm their identity. Passwords should be hashed using a strong hashing algorithm like bcrypt before being stored in the database to protect user credentials.

// Send verification email to user upon registration
$to = $email;
$subject = "Verify Your Email Address";
$message = "Please click the following link to verify your email address: http://example.com/verify.php?email=$email&token=$token";
$headers = "From: admin@example.com";
mail($to, $subject, $message, $headers);

// Hash the user's password before storing it in the database
$hashed_password = password_hash($password, PASSWORD_DEFAULT);

// Verify user's password during login
if (password_verify($input_password, $stored_hashed_password)) {
    // Password is correct, proceed with authentication
} else {
    // Password is incorrect, deny access
}