Jump to content

Recommended Posts

----------------------------------------------------------this code----------------------------------------------------------------------

<?php if($login_incorrect){  

  if(isset($_COOKIE['login'])){           if($_COOKIE['login'] < 3){               $attempts = $_COOKIE['login'] + 1;               setcookie('login', $attempts, time()+60*10); //set the cookie for 10 minutes with the number of attempts stored           } else{               echo 'You are banned for 10 minutes. Try again later';           }     } else{           setcookie('login', 1, time()+60*10); //set the cookie for 10 minutes with the initial value of 1     } } ?>

----------------------------------------------------in here----------------------------------------------------------------------------------

include('dbc.php');

if(isset($_POST['login']))
{ 
    $username=$_POST['username']; 
    $password=$_POST['password']; 
    if(empty($username) && empty($password))
{
    echo"<script>alert('please enter username and password')</script>";
}
if(empty($username) || empty($password))
{
    echo"<script>alert('please enter username and password')</script>";
}
 $pass= hash('sha512', $password);
     $set="Lecturer";
    $set2='Admin';
    
    $sel="select * from $tb1 where username='$username' and password='$pass'";
       $result=mysqli_query($con,$sel);
       $row=mysqli_fetch_array($result);
       
       if($row['username']== $username && $row['password']== $pass && $row['usertype']==$set)
       {
           $_SESSION["username"] = $_POST["username"];  
      $_SESSION['last_login_timestamp'] = time();  
            $_SESSION['username'] = $username;
            
            header('location:userhome.php');   }
 elseif ($row['username']== $username && $row['password']== $pass && $row['usertype']==$set2)
 {
     $_SESSION["username"] = $_POST["username"];  
      $_SESSION['last_login_timestamp'] = time();  
     $_SESSION['username'] = $username;
    header('location:adminhome.php'); 
}}
        else
       {echo"<script>alert('not registered/approved')</script>";}
     ?>

 

Did you write the script? If not, you might want to look into an alternative solution. For example, user-supplied information like what comes from $_POST['username'] should not be placed directly into the query. You will want to use prepared statements to prevent someone from performing SQL Injection attacks.

You should also look into a solution that uses password_hash() for hashing passwords. More information about hashing passwords can be found here:
https://www.php.net/manual/en/faq.passwords.php

What cyberRobot said and I'm not happy with the script the way it is because somewhere you need to be loading HTML for it to work and what I'm about to do does not take that into consideration:

	<?php
	if(isset($_POST['login'])){ 
	    if(isset($_COOKIE['login'])){           
	        if($_COOKIE['login'] < 3){               
	            $attempts = $_COOKIE['login'] + 1;              
	            setcookie('login', $attempts, time()+60*10);         
	        }else{
	/* Please note this is an ECHO while your using echo"<script>alert()</script>"; below */
	            echo 'You are banned for 10 minutes. Try again later';
	            die;          
	        }     
	    }else{           
	        setcookie('login', 1, time()+60*10);
	        die; 
	    } 
	/* I have include the rest of this so you have a formatted cody */
	    $username=$_POST['username']; 
	    $password=$_POST['password']; 
	    if(empty($username) && empty($password)){
	        echo"<script>alert('please enter username and password')</script>";
	    }
	    if(empty($username) || empty($password)){
	        echo"<script>alert('please enter username and password')</script>";
	    }
	    $pass= hash('sha512', $password);
	    $set="Lecturer";
	    $set2='Admin';
	    $sel="select * from $tb1 where username='$username' and password='$pass'";
	    $result=mysqli_query($con,$sel);
	    $row=mysqli_fetch_array($result);
	 
	    if($row['username']== $username && $row['password']== $pass && $row['usertype']==$set){
	        $_SESSION["username"] = $_POST["username"];  
	        $_SESSION['last_login_timestamp'] = time();  
	        $_SESSION['username'] = $username;
	        header('location:userhome.php');   
	    }elseif ($row['username']== $username && $row['password']== $pass && $row['usertype']==$set2){
	        $_SESSION["username"] = $_POST["username"];  
	        $_SESSION['last_login_timestamp'] = time();  
	        $_SESSION['username'] = $username;
	        header('location:adminhome.php'); 
	    }else{
	        echo"<script>alert('not registered/approved')</script>";
	    }
	}
	?> 
	

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.