W swojej klasie logowania mam problem z rozpoznawaniem wielkości liter. Kiedy próbuję się zalogować, pisząc nick z dużej litery, to jest ok loguje, ale jeśli z małej. Problem jest w tym, że kodowanie bazy jest ustawione na utf8_general_ci , więc nie powinno rozróżniać wielkości liter. Moduł Auth z frameworka Kohany, którego uzywam, ma to samo kodowanie i tam loguje normalnie jeśli wpiszę nick z małej litery.
Kod klasy
<?php
class Auth
{
private $username;
private $password;
private $salt;
private $pdo;
public $message;
public function __construct()
{
require_once ('config.php');
$this-> pdo= new PDO ($config['dsn'], $config['user'], $config['password']);
}
public function get_data()
{
$stmt= $this->pdo->prepare ('SELECT username,password,salt FROM users WHERE username=:username ORDER BY id');
$stmt-> bindValue (':username', $_POST['username'], PDO::PARAM_STR);
$stmt-> execute();
while ($row= $stmt-> fetch())
{
$this-> username= $row['username'];
$this-> password= $row['password'];
$this-> salt= $row['salt'];
}
$stmt-> closeCursor();
$this-> result= substr ($end - $start, 0
, 6
); }
public function login($username, $password)
{
if ($this-> username == $username && $this-> password == $this->code($password, $this->salt))
{
$_SESSION['user']= TRUE;
$this-> message= 'Welcome , ' . '<a href="auth.php?signout=true">Sign out</a>';
}
else
{
$this-> message= 'Invalid username/password';
}
}
public function signout()
{
if ($_GET['signout'] == TRUE)
{
header ("Location: login.php"); }
}
public function signup($username, $password, $email, $salt)
{
{
if ($this-> valid_email($_POST['email']) && $this->email_exists($_POST['email']))
{
$stmt= $this->pdo->prepare ('INSERT INTO users (username,password,email,salt)
VALUES (:username,:password,:email,:salt) ');
$stmt-> bindvalue (':salt', $salt,PDO::PARAM_STR);
$stmt-> execute();
$this-> message= 'Account has been created.';
$stmt-> closeCursor();
}
}
else
{
$this-> message= 'Fill in all fields.';
}
}
private function email_exists($email)
{
$stmt= $this->pdo->prepare ('SELECT email FROM users WHERE email=:email');
$stmt-> bindValue (':email', $_POST['email'], PDO::PARAM_STR);
$stmt-> execute();
if ($stmt-> fetch() > 0)
{
$this-> message= 'This email address exists.';
}
else
{
return true;
}
}
private function valid_email($email)
{
if (preg_match('/^[a-zA-Z0-9\.\-\_]+\@[a-zA-Z0-9\.\-\_]+\.[a-z]{2,4}$/D', $email)) {
return true;
}
else
{
$this-> message= 'E-mail is invalid.';
}
}
public function salt($pass)
{
}
public function code($pass, $salt)
{
return md5 ($pass . $salt); }
public function show()
{
return $this-> message;
}
}
$user= new Auth;
$user-> get_data();
$user-> login($_POST['username'],$_POST['password']);
$user-> signout();
?>