简体   繁体   中英

Case Sensitive PHP PDO login script

I made a simple login system with PDO function like $user->login. I allows user to login with username in any case like USER, user. How do i make this script case sensitive without altering the essence of the code.

<?php

require_once('includes/config.php');

if( $user->is_logged_in() ){ header('Location: topage.php'); } 

$message = "";

if(isset($_POST['submit'])){

  $username = $_POST['username'];
  $password = $_POST['password'];

  if($user->login ($username,$password)){ 
    $_SESSION['username'] = $username;
    header('Location: topage.php');
    exit;

  } else {
    $error[] = 'Wrong username or password or your account has not been activated.';
  }

}

?>

And also my password is salted using PDO command

$hashedpassword = $user->password_hash($_POST['password'], PASSWORD_BCRYPT);

and the Login function is

public function login($username,$password){

    $row = $this->get_user_hash($username);

    if($this->password_verify($password,$row['password']) == 1){

        $_SESSION['loggedin'] = true;
        $_SESSION['username'] = $row['username'];
        $_SESSION['memberID'] = $row['memberID'];
        return true;
    }
}

Use phpmyadmin to change the table column's collation to latin1_bin. Do this to the column you want to make case sensitive

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM