i have a problem with generating a one time password that will expire once used or after a few miute.
this is what i want to do
page 1. create a captcha. if verification is valid then direct me to page2
page 2. this page asks for my name or user-id, my php will check if name or user_id exists, if it exists it will generate a 6-digit code and email or sms to the mobile number
or email associated with the name or user_id that was given and direct to page 3.
the generated code should expire after 10minutes or after it has been used.
page 3. now this page will ask me to enter code that was sent to me. if code i enter is correct then it will allow me to change/update my password . script should update password at the user-id or name that was given
everything works perferct, only thing not working is code generation and sms or emailing of the code
i dont know what to now or how or where. please dont worry about the site not being secure or saving password
without encryption.
here is what i did so far
index.php
<?php session_start();
if(isset($_POST['Submit'])){
// code for check server side validation
if(empty($_SESSION['captcha_code'] ) || strcasecmp($_SESSION['captcha_code'], $_POST['captcha_code']) != 0){
$msg="<span style='color:red'>The Validation code does not match!</span>";// Captcha verification is incorrect.
}else{// Captcha verification is Correct. Final Code Execute here!
$msg="<span style='color:green'>The Validation code has been matched.</span>";
header("Location: userid.php");
}
}
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>verification</title>
<link href="./css/style.css" rel="stylesheet">
<script type='text/javascript'>
function refreshCaptcha(){
var img = document.images['captchaimg'];
img.src = img.src.substring(0,img.src.lastIndexOf("?"))+"?rand="+Math.random()*1000;
}
</script>
</head>
<body>
<form action="" method="post" name="form1" id="form1" >
<table width="400" border="0" align="center" cellpadding="5" cellspacing="1" class="table">
<?php if(isset($msg)){?>
<tr>
<td colspan="2" align="center" valign="top"><?php echo $msg;?></td>
</tr>
<?php } ?>
<tr>
<td align="right" valign="top"> Validation code:</td>
<td><img src="captcha.php?rand=<?php echo rand();?>" id='captchaimg'><br>
<label for='message'>Enter the code above here :</label>
<br>
<input id="captcha_code" name="captcha_code" autofocus type="text">
<br>
Can't read the image? click <a href='javascript: refreshCaptcha();'>here</a> to refresh.</td>
</tr>
<tr>
<td> </td>
<td><input name="Submit" type="submit" onclick="return validate();" value="Submit" class="button1"></td>
</tr>
</table>
</form>
</body>
</html>
userid.php
<?php
session_start();
require_once('mySQLConnect.php');
$error='';
$number='';
if (isset($_REQUEST['submit'])){
$user_id=$_REQUEST['user_id'];
$sql="SELECT * FROM members WHERE user_id= '$user_id'";
mysqli_query($conn,$sql);
$result=mysqli_query($conn,$sql);
$count=mysqli_num_rows($result);
if($count=='1'){
$sql2="SELECT phone FROM members where user_id= '$user_id'";
$result2=mysqli_query($conn,$sql2);
$row=mysqli_fetch_assoc($result2);
$number=$row["phone"];
header("Location: confirm.php?number=$number");
mysqli_free_result($result2);
}
else{
$error="USER_ID INCORRECT OR DOES NOT EXIST!<br>";
}
}
?>
<html>
<head>
<title>reset</title>
<style>
h1 {
color:#0C0;
}
.loadinggif
{
background:
url('img/spinner.gif')
no-repeat
right center;
}
span {
color:#C00;
font-family:"Lucida Sans Unicode", "Lucida Grande", sans-serif;
}
</style>
</head>
<body>
<center>
<form method="post" name="form1" id="form1">
<br><br>
<h1>enter your user-id to continue</h1>
<label for="test">user-id:</label>
<input type="text" name="user_id" id="user_id" autofocus required
placeholder="user-id" maxlength="7" ><br><br>
<span><?php echo $error ?></span><br>
<input type="submit" value="submit" name="submit" id="submit">
</form>
</center>
</body>
</html>
confirm.php
<?php
session_start();
require_once('mySQLConnect.php');
if (isset($_REQUEST['number'])) {
$number=$_REQUEST["number"];
}
?>
<html>
<head>
<title>confirm</title>
</head>
<style>
h1 {
color:#F93;
font-size:19px;
}
h2 {
color:#F00;
font-size:17px;
}
</style>
<body>
<center><br><br>
<form name="form1" method="post">
<h1>sms was sent to </h1><h2> <?php echo $number ?></h2>
<h1>please enter it below</h1>
<input type="text" name="code" id="code"><br><br>
<input type="submit" name="submit" value="submit">
</form>
</center>
</body>
</html>