HomePHPLogin & Signup Form with Email Verification using PHP and MySQL

Login & Signup Form with Email Verification using PHP and MySQL


Hello readers, Today in this blog you’ll learn how to create a Login & Signup Form with Email Verification using PHP and MySQL. Earlier I have shared a blog on How to configure XAMPP to send Mail from Localhost in PHP? If you haven’t still read this blog, then I want to suggest you first read that blog and continue this because in that blog I’ve taught you how to configure XAMPP before sending mail from the localhost.

As we all know, the login and & Signup Form is the set of different input fields – Name, Email, Username, Password, etc. which are used to authenticate users before giving access to the site. In our program [log in & Signup Form with Email Verification], there are eleven PHP files and one is a CSS file means there are a total of twelve files in our user name folder.Login & Signup Form with Email Verification using PHP and MySQLAt first, on the webpage, there is shown only a login form and inside the login form, there is a signup now link to redirect the user to the first signup before login. When the user tries to log in without even signup the form, there is displayed an error message labeled as “It looks like you’re not yet a member! Click on the bottom link to signup”.

In the signup form, while the user is signing up, if he enters the same email, which already exists in our database then there is displayed an error message labeled as “Email that you’ve entered is already exist!”. And when the user doesn’t match two password combinations, there is also displayed an error message labeled as “Your confirm password not matched”.

When the user filled up all the required inputs correctly, then a six-digit verification code number is sent to the user’s email and he will be redirected to the OTP Verification page. If the user entered the wrong code, there is displayed an error message labeled as “You’ve entered incorrect code!”. If the user exit the OTP verification code page without entered a valid or correct verification code and come to the login page to log in with the same email and password which he used to sign up, then he will be again redirected to the OTP page and there is displayed an info message labeled as “It looks like you’ve not verified your email”.

When the user entered the correct verification code, then he will be redirected to the Home Page. On the home page, there is a navbar with a logo on the top left corner and the logout button on the top right corner. At the center of the home page, there is a welcome message with the name of the user which he entered while signing up for the form. And when the user clicked on the logout button, he will be redirected to the login page and at this time he can log in with their correct email and password and will be directly redirected to the home page without redirecting to any other page.

If you’re feeling difficult to understand what I am saying. You can watch a full video tutorial on this program (Login & Signup Form with Email Verification).

Video Tutorial of Login & Signup Form with Email Verification

 
In the video, you have seen the demo of this project and I hope you love it. In this project, I have sent mail from Localhost using PHP and you must have to configure your XAMPP to Send Mail from Localhost in PHP. If you don’t configure your XAMPP then your mail which is used to send OTP code to the user won’t be sent and there is no meaning to download the source files of this project.

Login & Signup Form with Email Verification [Source Codes]

Click the given download button and you’ll be redirected to the timer page, just wait until the timer completed. Once the timer complete then the zip file will automatically download. Once you download the zip file, just extract it and you’ll get a folder with all required coding files with a userform.sql file. After these, create the database and the database name must be userform then import the userform.sql file by clicking on the import tab in the database. This file will create all required tables with columns. That’s it you don’t need to do anything more.

 


RELATED ARTICLES

261 COMMENTS

  1. i did solve the error u just need to use phpmailer instead of ()mail

    u need to install php mailer in your vs code
    first open your terminal in vs code and paste this composer require phpmailer/phpmailer
    then it will be success.
    second modify the controllerUserData.php “if user signup button” change the old to this

    // Include PHPMailer
    use PHPMailer\PHPMailer\PHPMailer;
    use PHPMailer\PHPMailer\Exception;

    require ‘C:\xampp\htdocs\Login\vendor\autoload.php’; // If using Composer
    // require ‘path/to/PHPMailer/src/Exception.php’;
    // require ‘path/to/PHPMailer/src/PHPMailer.php’;
    // require ‘path/to/PHPMailer/src/SMTP.php’; // If not using Composer

    //if user signup button
    if(isset($_POST[‘signup’])){
    $name = mysqli_real_escape_string($con, $_POST[‘name’]);
    $email = mysqli_real_escape_string($con, $_POST[’email’]);
    $password = mysqli_real_escape_string($con, $_POST[‘password’]);
    $cpassword = mysqli_real_escape_string($con, $_POST[‘cpassword’]);

    if($password !== $cpassword){
    $errors[‘password’] = “Confirm password not matched!”;
    }

    $email_check = “SELECT * FROM usertable WHERE email = ‘$email’”;
    $res = mysqli_query($con, $email_check);

    if(mysqli_num_rows($res) > 0){
    $errors[’email’] = “Email that you have entered is already exist!”;
    }

    if(count($errors) === 0){
    $encpass = password_hash($password, PASSWORD_BCRYPT);
    $code = rand(999999, 111111);
    $status = “notverified”;

    $insert_data = “INSERT INTO usertable (name, email, password, code, status)
    values(‘$name’, ‘$email’, ‘$encpass’, ‘$code’, ‘$status’)”;

    $data_check = mysqli_query($con, $insert_data);

    if($data_check){
    $mail = new PHPMailer(true);

    try {
    //Server settings
    $mail->isSMTP();
    $mail->Host = ‘smtp.gmail.com’; // Set the SMTP server to send through
    $mail->SMTPAuth = true;
    $mail->Username = ‘your_email_address’; // SMTP username
    $mail->Password = ‘your app password’; // SMTP password
    $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; // Enable TLS encryption
    $mail->Port = 587; // TCP port to connect to

    //Recipients
    $mail->setFrom(‘your_email_address’, ‘Mailer’);
    $mail->addAddress($email); // Add a recipient

    // Content
    $mail->isHTML(true);
    $mail->Subject = ‘Email Verification Code’;
    $mail->Body = “Your verification code is $code”;

    $mail->send();

    $info = “We’ve sent a verification code to your email – $email”;
    $_SESSION[‘info’] = $info;
    $_SESSION[’email’] = $email;
    $_SESSION[‘password’] = $password;
    header(‘location: user-otp.php’);
    exit();
    } catch (Exception $e) {
    $errors[‘otp-error’] = “Message could not be sent. Mailer Error: {$mail->ErrorInfo}”;
    }
    } else {
    $errors[‘db-error’] = “Failed while inserting data into database!”;
    }
    }
    }

    third rename this path to your path.
    require ‘C:\xampp\htdocs\Login\vendor\autoload.php’; // If using Composer

    fourth to get the app password you must go to google user accounts then find the security>on f2A authentication>search app password>create app>paste the password no space. $mail->Password = ‘your app password’; // SMTP password

    fifth do not use this link https://www.codingnepalweb.com/configure-xampp-to-send-mail-from-localhost/ because i tried to work on this and its showing error and the only solution is to use the phpmailer.

  2. ?php require_once “controllerUserData.php”; ?>

    THIS WORK?~

    IS this correct for the other pages I want to control access to?

  3. How to Set Google ReCaptcha In Your Login & Signup Form with Email Verification using PHP and MySQL PHP.

    Please Help Sir.

  4. Hey there CodingNepal, this is awesome! But I have a problem. I keep on getting errors even though I started both Apache and MySQL on xampp and I made the userform table and imported the file. Could you do a video on making this whole login and signup system? It would be great help. Thanks.

  5. I have successfully configured the files and the smtp settings in xampp. Now it says the verification code has been sent to the email but no verification code is received? Can you please help me out here

  6. Please how can I password protect the user profile settings page after login, where the user have to enter their registered password only, without username or email to gain Access

  7. You are the best @CodingNepal.. Thank you for this wonderful blog and for releasing your source code…. Much love from Nigeria

  8. Hello,
    Everything works perfectly with Mysql and my web server. I was able to customize the colors and translated into French all the pages. On the other hand, when I try to translate “notverified” and “verified” by “non” and “oui” in the file “controllerUserData.php”, the email sends me the verification code and after having added it and weighed on the button, it still asks me for the code and I can not go further in the operation.
    Can you help me?
    Thank you for this wonderful system.
    From Québec, Canada

  9. Create Video on creating database for this project

    Because when i click on sign up button it says – Failed while inserting your data into database

    Please…

  10. Hi Bro Impressive Work, I have used these scripts for a long time and it working on a local and live servers with a little tweak.

    Can you add csrf protection in the next version and when will your next versin be out?

  11. Hi I downloaded your project it works good. However I tried changing around stuff on the css page like background color and stuff but when I save and reload the content doesn’t change on the html page. Do you know why ?

  12. helloo bro
    you have a wondeful project but i have tried to use it on one of my html website but it gives me error pls can you just write to me how to do that or integrate if its possible please i am pleading in the name of God please”’thanks…

  13. Why it doesn’t send a OTP in my email address but the code is available in the server and if i use the test.php file it can send the message “Hi, there…This is a test email send from Localhost.” to the email. Is the controllerUserData.php code has the problem?

  14. Always when I used to search any coding at last I used to put coding Nepal because here everything is like beautiful and I like this website one day I will make a video about this but this website will be treasure to you and me at finally with fun I really enjoy it with myself you also search anything by here defiantly you can gain an understanding mode hope this enjoyment is great

  15. Hi bro codingnepal I saw your video but I have confused because I saw two different videos of sending email messages and they’re 1:mail ()function
    2:smtp,
    So what are the difference between these two methods

  16. Can i use this codes on my website? i will give credits at the bottom.
    I will style these forms as much as i can just i need the php codes for i know a bit php but not so much advanced php and i was looking for sth just like this

  17. Thanks a lot for the source code sir, everything is working properly but only one thing is showing error , and that is “forget password” option.
    in that after entering the email ,when i click on “continue” it shows error .
    The requested URL was not found on this server.

    Apache/2.4.48 (Win64) OpenSSL/1.1.1k PHP/8.0.9 Server at localhost Port 80

    can you plz help me in solving that ?
    rest of the files are perfect

  18. Hello
    first of all i will like to appreciate your work. You are doing a great and awesome job. Thank you.
    Now my question: How can remove the otp verification option form the form?

  19. Could you please show about phpmyadmin setup for this form? Like how to place otp and verification status from phpmyadmin

    • Please, read the blog properly. You don’t need to set up or create a database for this login form. I already provided a SQL file that creates a required table, columns.

  20. hey codingNepal pls tell like if i add this page i want that after all these steps my original website opens…how to do that?

  21. your code works fine on localhost, but on live server it was showing error on signup “failed while inserting data in database”. i am using namecheap hosting where creating new database will save db name as “diamqpuj_userform” and not how i want “userform” and it saves username like that as well. i did change my connection file with db name as “diamqpuj_userform” same with username as well but still it is showing error don’t know why.

    • I’m really sorry for this but please make sure ads are showing on this site because your browser may have blocked the ads.

  22. Hii please help me I am student and I am learning it.

    Querry: When I sign-up in this it’s show unable to send data into database and too many errors I am unable so solve it please help me. and Make Video on how to create My SQL database and connect database to this login, sign-up system please reply me. and make video I am waiting for you.

    • Maybe, your config file database name is not matched with your database. Please read the blog for it.

  23. if yes please let me know the configuration, if no then what steps i need to follow , as i don’t have xampp if you need me to install it i will do it or any other solution except installation please provide i am waiting

  24. is there anyway to configure it to wampp server please let me know i love your coding tutorials please solve my problem

    • Hello, I’m really sorry because I haven’t used wamp so please install xampp and follow the steps for this login form.

  25. You guys are the best pls is there any tutorial on how to create a login form/registration form that when the user enters a specific code it registers the user and will lead the user to a page where he can save files and get those files back pls help me out am a new developer and finding it difficult

  26. I did was change my email in the controllerUserData.php and configure xampp settings, still getting the error alert: Failed while sending code!

  27. hi what does this mean?

    Warning: mail(): Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:wamp64wwwportalcontrollerUserData.php on line 33

  28. Hi Coding Nepal, all your codes works so well! and it has helped along the way! But now Is there to make this like a membership system. I need your help on that.

  29. Can you please make these scripts with PDO (prepared elements)? I'm using this for my school project, and my host needs scripts with PDO.
    Thanks! Your code helped, but I'm afraid that I need to ask this little favor of yours again.

  30. Hey Bro! Nice Work!
    I want to ask that can we connect this to html site?
    Like After Complete signing up, redirect to html site? Is It Possible Or We Need PHP Site?
    please reply.
    BTW THANKS FOR AWESOME STUFF

  31. works perfectly. but still didn't recieve any mail. xampp is configured and all but i still didn't receive the code in my gmail. followed other's suggestion like enabling IMAP in gmail setting and less secure. still didn't recieve the code. any suggestions?

  32. You have to verify or compare user password with SHA because your DB passwords are encrypted and when user try to login, his/her password is in plain text so you've to compare it with SHA. I recommended do not use SHA. It can decrypt easily. Use password_hash.

  33. Hi, SUPER TY. All work fine. Can you help me with this?, Im trying put this function for encrypt the password.

    function l2j_encrypt($password){
    return base64_encode(pack("H*", sha1(utf8_encode($password))));

    I encrypt the password in (signup-user.php / new-password.php). But, I can't use the password with this encrypt here (login-user.php). TY again <3, im wait for your answer.

  34. Warning: mail(): Failed to connect to mailserver at "localhost:8080" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:xampphtdocsTDM202grcontrollerUserData.php on line 33

  35. Warning: mail(): Failed to connect to mailserver at "localhost:8080" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:xampphtdocsTDM202grcontrollerUserData.php on line 118

  36. Hi, I have been getting this errors this errors frequently "Failed while inserting data into database!"

    I think The problem is from the data_check, I have tried selecting before inserting, but unto no avail, kindly help check the code again. Thanks

  37. Warning: mail(): Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:XAMPP1htdocsloginformcontrollerUserData.php on line 33
    Signup Form

  38. My browser is taking forever to download the source code. Infact, it is just showing "The file will start downloading in 30 seconds time", but nothing happens after the said 30 seconds.

    Another thing, do you have a tutorial on how to auto arrange popular Posts using post hits/visits, and configuring social media sharing buttons

  39. Warning: mail(): SMTP server response: 530 5.7.0 Must issue a STARTTLS command first. 22sm22663187pfn.190 – gsmtp in C:xampphtdocsLogin and Signup Form with Email Verification – PHPcontrollerUserData.php on line 33

    what should i do sir. please help

  40. Nice Job! But I have a problem it says "Warning: mail(): Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:xampphtdocscontrollerUserData.php on line 33" My code is the same as yours |Failed while sending code!" Can you help me?

  41. Hii,
    i have one error when i register new account it shows

    "Failed while inserting data into database!"
    i had check my database name but its correct so where is problem.
    please help me to solve this error

  42. Failed while sending code!
    I was trying to implement it in my hosting .But I am getting this error. But data perfectly saved in database,since I changed few necessary changes to connect with my hosting databases.Now my question is why I am facing this error?
    please help me and thanks a lot for this great tutorial.

  43. Create a php file inside the HTDOCS folder with .php extension and paste the following codes in this file then put the receiver email and sender email address in the mentioned fields.

  44. Warning: mail(): SMTP server response: 530 5.7.0 Must issue a STARTTLS command first. 78sm5550625pfz.211 – gsmtp in C:xampphtdocsLogin and Signup Form with Email Verification – PHPcontrollerUserData.php on line 33 (Failed while sending code)

    where the last php file should be save and with which name plz specify.

  45. good job
    What is the step to take after downloading the files and programming Xampp ? Where should I place my php file in " How to configure XAMPP to send Mail from Localhost in PHP ?"

    • even i had the problem with this then i figured out that you’ve got to create the database first by importing the sql file then this error will disappear inshallah.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Recent Posts

Featured Post

Categories

AdBlock Detected