Should a social network site allow UTF-8 in usernames and passwords? I'm really new to PHP and I would like to know such things. I'm creating a little test project right now and I have set the collation to utf8_general_ci and SET NAMES utf8. Everthing is being inserted and displayed correctly with characters like "ÅÄÖ". But if the username or the password contain those characters you won't be able to log in. Why?
<?php
if(isset($_POST['loginBtn'])){
//variables
$username = mb_strtolower(strip_tags(addslashes($_POST['username'])));
$password = strip_tags(addslashes($_POST['password']));
if(empty($username) || empty($password)){
$statusM = "Var god och fyll i båda fälten!";
}else{
//$password = hash("sha512", $password);
include("db.php");
//the db.php contains the character set and collation set
$sql = 'SELECT username, password FROM users WHERE username=:username AND password=:password';
$stmt = $db->prepare($sql);
$stmt->bindParam(":username", $username);
$stmt->bindParam(":password", $password);
$stmt->execute();
if(!$stmt->rowCount() > 0){
$statusM = "Antingen fel lösenord eller användarnamn!";
}else{
$sql = 'SELECT * FROM users WHERE username=:username AND password=:password';
$stmt = $db->prepare($sql);
$stmt->bindParam(":username", $username);
$stmt->bindParam(":password", $password);
$stmt->execute();
$stmt->setFetchMode(PDO::FETCH_ASSOC);
$row = $stmt->fetch();
session_start();
$_SESSION['school'] = $row['school'];
$_SESSION['firstname'] = $row['firstname'];
$_SESSION['lastname'] = $row['lastname'];
$_SESSION['username'] = $row['username'];
$_SESSION['password'] = $row['password'];
$_SESSION['email'] = $row['email'];
header("Location: member_home.php");
exit();
}
}
}
?>
NOTE, this is my current code and it is not done AND the site is in swedish.