Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if (isset($_POST['btn-login']))
- {
- $LoginID = mysqli_real_escape_string($conn, $_POST['username']);
- $Password = $_POST['password'];
- $sql = "SELECT *, SUBSTRING_INDEX(Name, ' ', 1) AS ShortName FROM users_db WHERE UserID = '".$LoginID."'";
- $res = mysqli_query($conn, $sql);
- $row = mysqli_fetch_array($res);
- $count = mysqli_num_rows($res); // if username/pass correct it returns must be 1 row
- if($count < 1 )
- {
- echo "errmsg1";
- }
- else if($count == 1 && $row['Password']==password_verify($Password, $row['Password']) && $row['AccountStatus']=="Pending")
- {
- echo "errmsg2";
- else if($count == 1 && $row['Password']==password_verify($Password, $row['Password']) && $row['AccountStatus']=="Active")
- //session variables set here.
- }
- else
- {
- echo "errmsg3";
- }
- }
- <script>
- /*
- Login Validation Script
- */
- $('document').ready(function()
- {
- /* validation */
- $("#login-form").validate({
- rules:
- {
- password: {
- required: true,
- },
- username: {
- required: true,
- },
- },
- messages:
- {
- password:{
- required: "Password field cannot be empty."
- },
- username:{
- required: "A Login ID is required."
- },
- },
- submitHandler: submitForm
- });
- /* validation */
- /* login submit */
- function submitForm()
- {
- var data = $("#login-form").serialize();
- $.ajax({
- type : 'POST',
- url : 'processlogin.php',
- data : data,
- beforeSend: function()
- {
- $("#loginerror").fadeOut();
- $("#btn-submit").html('<img src="include/btn-ajax-loader.gif" /> Verifying');
- },
- success : function(response)
- {
- if(response=="success"){
- $("#btn-submit").html('<img src="include/btn-ajax-loader.gif" /> Signing In...');
- setTimeout(' window.location.href = "index.php"; ',4000);
- }
- else if(response=="errmsg1"){
- $("#loginerror").fadeIn(1000, function(){
- $("#loginerror").html('<span>The Login ID provided does not exist.</span>');
- $("#btn-submit").html('Login');
- });
- }
- else if(response=="errmsg2"){
- $("#loginerror").fadeIn(1000, function(){
- $("#loginerror").html('<span>This account is Pending Activation.</span>');
- $("#btn-submit").html('Login');
- });
- }
- else if (response=="errmsg3"){
- $("#loginerror").fadeIn(1000, function(){
- $("#loginerror").html('<span">Unknown Error</span>');
- $("#btn-submit").html('Login');
- });
- }
- }
- });
- return false;
- }
- /* login submit */
- });
- </script>
- catch(PDOException $e){
- echo $e->getMessage();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement