mardi 24 mars 2015

php mysql login not working [duplicate]


This question already has an answer here:




I'm trying to write a php script to login to a website. I'm very new to all of this and have been looking at it for probably about 2 days now. I've tried to write a script that I've compiled from a couple of sources online to try and do what I want to do. But for some reason it isn't working. I think it is disagreeing somewhere around the if(!empty($_POST)) { part but I can't see exactly what it is. I'm using Brackets to write it all and it keeps having issues with the } to close the if statement, but I can't see where they're not balanced.



<?php
function db_connect() {
static $connection;
if(!isset($connection)) {
$config = parse_ini_file('../private/config.ini');
$connection = mysqli_connect('localhost',$config['username'],$config['password'],$config['dbname']);
}
if($connection === false) {
return mysqli_connect_error();
}
return $connection;
}

function db_query($query) {
$connection = db_connect();
$result = mysqli_query($connection, $query);
return $result;
}

function db_error() {
$connection = db_connect();
return mysqli_error($connection);
}

$submitted_username = '';

if(!empty($_POST)) {
$username = $_POST['username']
$query = db_query("SELECT * From users where username = $username)";
$result = mysqli_query($connection, $query);
$login_ok = false;
if($result) {
$check_password = hash('sha256', $_POST['password'] . $result['salt'];
for($round = 0; $round < 65536; $round++) {
$check_password = hash('sha256', $check_password . $row['salt']);
}
if($check_password === $row['password']) {
$login_ok = true;
}
}}
if($login_ok) {
unset($row['salt']);
unset($row['password']);
$_SESSION['user'] = $row;
header("Location: Dashboard.php");
die("Redirecting to: Dashboard.php");
} else {
print("Login Failed.");
$submitted_username = htmlentities($_POST['username'], ENT_QUOTES, 'UTF-8');
}

?>

Aucun commentaire:

Enregistrer un commentaire