I have successfully managed to store a hashed password in my database when the user creates an account, however, when they goto login ,with the correct password it returns the 'wrong password' error message i implemented.
$username = ($_REQUEST['username']);
$password = ($_REQUEST['password']);
if(isset($username) && isset($password)){
$sql = "SELECT password FROM users WHERE username = '$username';";
$result = mysqli_query($con, $sql);
$row = mysqli_fetch_array($result, MYSQLI_ASSOC);
$storedpw = $row['password'];
//checking the stored pw against the enetered one
if(password_verify($password, $storedpw)) {
mysqli_close($con);
$_SESSION["userVal"] = $username;
$_SESSION["user_image"] = $image;
header("location: adminPage.php");
} else {
$errmsg = "Invalid Username or Password.";
}
}
When i run this i am being given the error message from php
[Mon May 30 14:14:10.631018 2016] [:error] [pid 7928:tid 1492] [client ::1:54231] PHP Notice: Undefined index: username in D:\UniServerZ\www\GRADEDUNIT1\login2.php on line 19
[Mon May 30 14:14:10.631018 2016] [:error] [pid 7928:tid 1492] [client ::1:54231] PHP Notice: Undefined index: password in D:\UniServerZ\www\GRADEDUNIT1\login2.php on line 20
[Mon May 30 14:14:10.631018 2016] [:error] [pid 7928:tid 1492] [client ::1:54231] PHP Notice: Undefined variable: errmsg in D:\UniServerZ\www\GRADEDUNIT1\login2.php on line 106
However when i echo out the variables they are defined. from the login form
<form action="" method="post">
<input type="text" name="username" placeholder="Username" class="input" />
<input type="password" name="password" placeholder="Password" class="input" />
<br/><br/>
<!--<div class="g-recaptcha captcha" data-sitekey="6LcLdyATAAAAAE3WODrfikLzWadSCUKzhfuxFEXf"></div>
<br/>-->
<input type="submit" class="button button-primary" value="Log In" id="login"/>
</form>
So my ultimate question is why is this returning false when it should be a match? I have written out the MySQL statement and checked it, it seems fine! I stuck.