Skip to main content

Email Verification With OTP-One Time Password


 How to integrate OTP(One Time Password) in PHP form

Hello friends ajj me apko btaunga ki ham simple email otp verification script kaise bana sakte hai.

App demo niche diye gye link se check kar sakte ho;


Demo-    OTP Email Verification Script





Index2.php

<center><form action="mail.php" method="post">

Name:<input type="text" name="firstname">


Email:<input type="text" name="username">

Phone:<input type="text" name="lastname">


<input type="submit" name="submit" value="submit">

</form>

</center>

Index2.php file ki help se hamne front end ke liye ek form bnaya hai jiska use kerke user apne information,signup karega






mail.php




<center>

<?php

session_start();

$code=rand(22222,99999);

$_SESSION["code"]=$code;

$username=$_POST['username'];

$firstname=$_POST['firstname'];

$lastname=$_POST['lastname'];

$_SESSION["username"]=$username;

$_SESSION["firstname"]=$firstname;

$_SESSION["lastname"]=$lastname;

require 'PHPMailer-master/PHPMailerAutoload.php';



$mail = new PHPMailer();



  //Enable SMTP debugging.

  $mail->SMTPDebug = 0;

  //Set PHPMailer to use SMTP.

  $mail->isSMTP();

  //Set SMTP host name

  $mail->Host = "smtp.gmail.com";

  $mail->SMTPOptions = array(

                    'ssl' => array(

                        'verify_peer' => false,

                        'verify_peer_name' => false,

                        'allow_self_signed' => true

                    )

                );

  //Set this to true if SMTP host requires authentication to send email

  $mail->SMTPAuth = TRUE;

  //Provide username and password

  $mail->Username = "yourgmailidhere@gmail.com";

  $mail->Password = "yourgmailpassword";

  //If SMTP requires TLS encryption then set it

  $mail->SMTPSecure = "false";

  $mail->Port = 587;

  //Set TCP port to connect to



  $mail->From = "bhupenderkashyap122@gmail.com";

  $mail->FromName = "jignesh";



  $mail->addAddress($_POST["username"]);



  $mail->isHTML(true);

$mail->addAttachment('lop.jpg', 'lop1.jpg'); //set new name





  $mail->Subject = "test mail";

  $mail->Body = "<i>this is your password:</i>".$code;

  $mail->AltBody = "This is the plain text version of the email content";

  if(!$mail->send())

  {

   echo "Mailer Error: " . $mail->ErrorInfo;

  }

  else

  {

   echo "<h1>OTP has been send succesfully in Your email Id please checkout </h1>";



   ?>

  

   <form action="mail2.php" method="post">



<input name="captcha" type="text">





<input type="submit" name="submit" value="submit">

</form>

  

<?php





  }

  ?>









</center>



Yanha mail.php file me apko sirf apna gmail id ka username and password enter karna hai agar aap is script ko localhost par run karwa rahe ho.,mail.php file  me hamne rand function and php mailer library ka use kiya hai.yanha rand function random otp code generate karega  aur fir phpmailer library function ki madad se generate  hua random otp user ki email id par jayega..






  mail2.php


<center>

<br>

<br>

<br>

<br>

<br>





<?php

session_start();

$code="";


if(isset($_POST["captcha"])&&$_POST["captcha"]!=""&&$_SESSION["code"]==$_POST["captcha"])

{

echo $captcha=$_POST['captcha'];

echo "<br>";

echo "Correct Code Entered";



include 'insert.php';







session_destroy();

//Do you stuff

}

else

{

echo "Wrong Code Entered Try Again";







?>









<form action="mail2.php" method="post">



<input name="captcha" type="text">



<input type="submit" name="submit" value="submit">

</form>

















<?php } ?>



<a href="index2.php">Index</a>

</center>

<center>






</center>

mail2.php  file validate karegi ki user dawara enter kiya gya otp ,and userki email id par gya otp code same hai ya nhi,ye work yanha ham session ki madad se karege
.





insert.php


<?php





$conn=mysqli_connect("localhost","root","","google");

//enter your database detail Here



if(isset($_SESSION['username'])) {

  echo "Your session is running " . $_SESSION['username'];



$username=$_SESSION['username'];

$firstname=$_SESSION['firstname'];

$lastname=$_SESSION['lastname'];

$sql = "INSERT INTO otp(username,firstname,lastname)

VALUES ('$username','$firstname','$lastname')";



mysqli_query($conn, $sql);



}



?>

Insert.php file ka kam hai ki agar user correct otp code  enter karta hai to user ke information firstname,lastname,and username ko databse me store kar lena.







Database code- -- phpMyAdmin SQL Dump

-- version 4.7.0

-- https://www.phpmyadmin.net/

--

-- Host: 127.0.0.1

-- Generation Time: Jun 19, 2018 at 08:11 AM

-- Server version: 10.1.26-MariaDB

-- PHP Version: 7.1.8



SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";

SET AUTOCOMMIT = 0;

START TRANSACTION;

SET time_zone = "+00:00";





/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;

/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;

/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;

/*!40101 SET NAMES utf8mb4 */;



--

-- Database: `google`

--



-- --------------------------------------------------------



--

-- Table structure for table `otp`

--



CREATE TABLE `otp` (

  `id` int(10) NOT NULL,

  `username` varchar(255) NOT NULL,

  `firstname` varchar(255) NOT NULL,

  `lastname` varchar(255) NOT NULL

) ENGINE=InnoDB DEFAULT CHARSET=latin1;



--

-- Indexes for dumped tables

--



--

-- Indexes for table `otp`

--

ALTER TABLE `otp`

  ADD PRIMARY KEY (`id`);



--

-- AUTO_INCREMENT for dumped tables

--



--

-- AUTO_INCREMENT for table `otp`

--

ALTER TABLE `otp`

  MODIFY `id` int(10) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=4;COMMIT;



/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;

/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;

/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;

App complete CODE SCRIPT NICHE DIYE GYE link se download kar lijiye download karne ke bad apko is code me sirf mail.php file me apni gmail id and password enter karke save kar dena hai or sath he databse file ko mysql me import karna hai takki user ki information mysql databse me store ho sakte correct otp enter karne ke bad.

Download Full Email OTP Verification Script

Thank You

Team Gajabwap Web In Hindi


Comments

  1. maine sare file ka code likh liya bana bhi liya aur PHPMailer file bhi hai mail.php me email and password apna add ki database bhi hai but error aa raha hai ye Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

    ReplyDelete
  2. Bro ye code sirf web hosting me work krega pehle aap web hosting me sare code files upload kro wanha ye perfectly work krega

    ReplyDelete
  3. Today we will Discuss One interesting Topic OTP Bypass ! How hackers able to Bypass OTP Schema On Web Or Mobile based application. As You know A one-time password (OTP) is an automatically generated numeric or alphanumeric string of characters that authenticates the user for a single transaction or login session.

    ReplyDelete

Post a Comment

Popular posts from this blog

How to Download Vimeo Thumbnail With PHP

Vimeo Thumbnail Downloader Tool – Vimeo Video Ka Thumbnail Download Karein Aaj ke is tutorial mein hum Vimeo Thumbnail Downloader Tool ke baare mein jaanenge. Is tool ki help se hum Vimeo video URL se us video ki thumbnail image obtain kar sakte hain. Agar aap PHP, Web Development, HTML, CSS aur Online Tools banana seekh rahe hain, to ye ek useful PHP project example hai. Vimeo Thumbnail Downloader Kya Hai? Vimeo Thumbnail Downloader ek simple tool hai jisme user Vimeo video ka URL enter karta hai. Tool Vimeo video ID ko identify karta hai aur available thumbnail image ko display karta hai. Example Vimeo URL: https://vimeo.com/389063954 Is URL mein: 389063954 Vimeo video ID hai. Vimeo Thumbnail Downloader Kaise Work Karta Hai? Is PHP script mein mainly do functions use kiye gaye hain: 1. getVimeoId() Ye function Vimeo URL se video ID find karta hai. 2. getVimeoThumb() Ye function Vimeo video ID ke basis par thumbnail information retrieve karta hai aur available thumbnail...

How To Create Contact Form With Validation-Php & Html

How To Create Contact Form - Hello Friends Ajj Me Apko Btaunga   Ki Kis Prakar   Ham Apni Website Ke Liye Contact Form Bnana Sakta Hai.( By Using   Php Contact Form With Validation Script ) Contact Form Hmare Website Ke Liye Bhut He Jrruri Hota Hai.Contact Form Ke Help Se He User Apna Message Website Owner(Admin) Ko Bhej Sakte Hai. Ajj Me Apko Btane Wala Hu Ki Kis Parkar Ham Contact Form Banakar Apne Website Me Add Kar Sakte Hai Or Apni Website Ke Liye Contact Form Bana Sakte Hai Is Contact Form Me   Ham Php Mail Function() Ka Use Karege . Ab Jab Be Koi User Contact Form Me Apni Information ,Message Details Fill Karke Submit Karega To Uski Sare Information Website Admin Ke Email Id Par A Jaiyegi Jo Be Admin Dwara   Niche Diye Gye Code Me Setup Ki Hogi. Used Language- ·          HTML ·          Jquery ·          Php ...

How To Send Sms From Website Using Php-Textlocal SMS

Hello Friends Ajj Me Apko Btaunga Ki Kis Prakar Aap Apni Website Me Free Sms Send Ka Option Integrate Kar Sakte Ho. Bulk sms in India-Best company Iske Liye Apko Sabse Pehle   Https://Www.Textlocal.In/Signup Par Signup Karke Account Create Karna Hai.Ye Ek Achi bulk sms provider company hai ·          Account Create Hone Ke Bad Aap Apna Username And Password Enter Karke Apne Dashboard Me Login Ho Jaiye( textlocal login) ·          Yanha Apko Text Local Company Dwara 10 Meassge Free Testing Ke Liye Diye Jayege ·          Aap Sms Plan Buy Kar Sakte Ho Is Company Dwara Bhut He Kam Prize Me Sms Pakage,plan provide  Kiye Jate Hai Textlocal Price Plans –  index.php <?php if(isset($_POST['code']) &&  isset($_POST['mobile'])){ // Authorisation details. $username = "enter your textlocal account email id here"; $hash = "...