How can I add email code authentication on form submission without any wp plugin?

I will show you the option if you know about the handler functions in php then you can follow the following sequence:

1. Create a function to check the form submission request, after checking the code from the form form successfully, the function will send mail to the user.

2. The function sends mail to the user via smtp to process sending mail right after the successful form check.

3. The function saves the data you want to the database after checking the form.

You can create these steps through a form action in php, or create a function to use ajax. In addition to saving data to the DB, you can use functions in php or if using pure wordpress, you can use $wpdb->insert

https://developer.wordpress.org/reference/classes/wpdb/insert/