15.09.2017, 09:11
Moin,
hab ein Problem mit password_verify.. password_hash wird nach erfolgreicher Registrierung im DB-Feld 'password' zum dazugehörigen User erfolgreich abgelegt.
Allerdings kriege ich kein Match, wenn ich mich dann einloggen will..
Hier mal die PHP:
hab ein Problem mit password_verify.. password_hash wird nach erfolgreicher Registrierung im DB-Feld 'password' zum dazugehörigen User erfolgreich abgelegt.
Allerdings kriege ich kein Match, wenn ich mich dann einloggen will..
Hier mal die PHP:
PHP-Code:
<?php
require('db.php');
function redirect($DoDie = true) {
header('Location: success.php');
if ($DoDie)
die();
}
session_start();
if(isset($_SESSION['username'])) {
redirect();
}
// If form submitted, insert values into the database.
if (isset($_POST['username'])){
$username = stripslashes($_REQUEST['username']); // removes backslashes
$username = mysqli_real_escape_string($con,$username); //escapes special characters in a string
$password = stripslashes($_REQUEST['password']);
$password = mysqli_real_escape_string($con,$password);
$hash_query = "SELECT password FROM `user` WHERE username='$username'";
$hash_result = mysqli_query($con,$hash_query) or die(mysql_error());
$ipaddress = $_SERVER['REMOTE_ADDR'];
//Checking is user existing in the database or not
$query = "SELECT * FROM `user` WHERE username='$username' and password='$password'";
$result = mysqli_query($con,$query) or die(mysql_error());
$rows = mysqli_num_rows($result);
if($rows==1){
if (password_verify($password, $hash_result)) {
$_SESSION['username'] = $username;
$trn_date = date("Y-m-d H:i:s");
$query = "UPDATE `user` SET `ip` = '$ipaddress', `last_login` = '$trn_date' WHERE `username` = '$username'";
$result = mysqli_query($con,$query) or die(mysql_error());
$rows = mysqli_num_rows($result);
header("Location: success.php"); // Redirect user to index.php
}
else {
header("Location: error.php");
}
}
else {
header("Location: error.php");
}
}
else {
?>
Vielleicht kann mir jemand helfen.