Skip to content

Instantly share code, notes, and snippets.

@shivasurya
Created May 11, 2014 02:04
Show Gist options
  • Save shivasurya/83c11f44f2079c145ee5 to your computer and use it in GitHub Desktop.
Save shivasurya/83c11f44f2079c145ee5 to your computer and use it in GitHub Desktop.
i-visionblog.com loginv1.0 index.php file
<head>
<link href="css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="css/validator/css/bootstrapValidator.min.css"/>
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<script type="text/javascript" src="css/validator/js/bootstrapValidator.min.js"></script>
<script>
$(document).ready(function() {
$('#attributeForm').bootstrapValidator();
});
</script>
</head>
<?php
session_name('hipsterlabs');
session_start();
$publickey="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX public key here";
function d()
{ $_SESSION['access']=generateRandomString();
$_SESSION['mode']="form";
?>
<center>
<div style="">
<h3>Google Recaptcha enabled login system</h3>
<form action="login.php" method="post" id="attributeForm" class="form-horizontal" data-bv-message="This value is not valid" data-bv-feedbackicons-valid="glyphicon glyphicon-ok" data-bv-feedbackicons-invalid="glyphicon glyphicon-remove" data-bv-feedbackicons-validating="glyphicon glyphicon-refresh" >
<div class="form-group">
<label class="col-lg-3 control-label">Email address</label>
<div class="col-lg-5">
<input class="form-control" name="username" type="email"
data-bv-emailaddress="true"
data-bv-emailaddress-message="The input is not a valid email address"
data-bv-notempty="true"
data-bv-notempty-message="The password is required and cannot be empty" />
</div>
</div>
<div class="form-group">
<label class="col-lg-3 control-label">password</label>
<div class="col-lg-5">
<input type="password" name="passwd" id="passwd" class="form-control"
data-bv-notempty="true"
data-bv-notempty-message="The password is required and cannot be empty"
data-bv-different="true"
data-bv-different-field="username"
data-bv-different-message="The password cannot be the same as email" />
</div>
</div>
<div class="form-group">
<div class="col-lg-9 col-lg-offset-3">
<button type="submit" class="btn btn-primary">Login</button>
</div>
</div>
</form>
</div>
</center>
<?php
}
function displayformrecap()
{$_SESSION['access']=generateRandomString();
?> <center>
<div style="">
<h3>Google Recaptcha enabled login system</h3>
<form action="login.php" method="post" id="attributeForm" class="form-horizontal" data-bv-message="This value is not valid" data-bv-feedbackicons-valid="glyphicon glyphicon-ok" data-bv-feedbackicons-invalid="glyphicon glyphicon-remove" data-bv-feedbackicons-validating="glyphicon glyphicon-refresh" >
<div class="form-group">
<label class="col-lg-3 control-label">Email address</label>
<div class="col-lg-5">
<input class="form-control" name="username" type="email"
data-bv-emailaddress="true"
data-bv-emailaddress-message="The input is not a valid email address"
data-bv-notempty="true"
data-bv-notempty-message="The password is required and cannot be empty" />
</div>
</div>
<div class="form-group">
<label class="col-lg-3 control-label">password</label>
<div class="col-lg-5">
<input type="password" name="passwd" id="passwd" class="form-control"
data-bv-notempty="true"
data-bv-notempty-message="The password is required and cannot be empty"
data-bv-different="true"
data-bv-different-field="username"
data-bv-different-message="The password cannot be the same as email" />
</div>
</div>
<?php
$_SESSION['mode']="recapform";
$_SESSION['access']=generateRandomString();
require_once('recaptchalib.php');
$error="";
echo recaptcha_get_html($publickey, $error); ?>
<div class="form-group">
<div class="col-lg-9 col-lg-offset-3">
<button type="submit" class="btn btn-primary">Login with recaptcha</button>
</div>
</div>
</form>
</div>
</center> <?php
//display form with recaptcha with access token generation
}
function check_session()
{
$catch = isset($_SESSION['userid']) ? true : false;
return $catch;
}
function generateRandomString($length = 10) {
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, strlen($characters) - 1)];
}
return $randomString;
}
if(check_session())
{
header("location: home.php");
}
else
{
$_SESSION['attempt'] = isset($_SESSION['attempt']) ? $_SESSION['attempt'] : 0;
$_SESSION['access']=generateRandomString();
if($_SESSION['attempt']>3)
{
displayformrecap();
}
else
{
d();
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment