Ahoj, ako by ste vhodne zabezpečili tento PHP script napríklad pre SQL injection, alebo XSS, robí sa to aj s HTMLspecialchars? :) Ďakujem za odpovede, prípadne za korektne upravený zdroják.
PHP kód:
<?php
include("functions.php");
session_start();
if(isset($_POST['odoslat'])){
$username = ($_POST['username']);
$password = ($_POST['password']);
$login_check = mysqli_query($con,"SELECT `id` FROM `user` WHERE `username`='$username' AND `password`='".sha1($password)."'") or die (mysqli_error($con));
if(mysqli_num_rows($login_check) == 0){
$echo = "Nesprávna kombinácia mena/hesla!";
}else{
$activated_check = mysqli_query($con,"SELECT `activated` FROM `user` WHERE `username`='$username' AND `password`='".sha1($password)."'") or die (mysqli_error($con));
$activated = mysqli_fetch_assoc($activated_check);
if($activated['activated'] == 0){
$echo = "Tento účet ešte nebol aktivovaný!";
}else{
$get_id = mysqli_fetch_assoc($login_check);
$_SESSION['uid'] = $get_id['id'];
header("Location: main.php");
$t = file_get_contents("prihlasenia.txt");
$today = date("Y-m-d H:i:s");
$t .= $today." Používateľ ".$username." "."sa prihlásil!"."\r\n";
file_put_contents("prihlasenia.txt",$t);
}
}
}
?>
HTML kód:
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="post" name="login" id="form-login">
<br />
<input type="text" name="username" alt="username" placeholder=Meno style="width:100%" />
<input type="password" name="password" size="18" alt="password" placeholder=Heslo style="width:100%" />
<button type="submit" name="odoslat" class="xmiddle blue button round">Prihlásiť!</button>
</fieldset>
<ul>
<li>
<a href="register.php">Vytvoriť účet</a>
</li>
</ul>
</form>