I am trying to create a log in system with session with php and mysql but i keep getting password error...











up vote
-1
down vote

favorite













This question already has an answer here:




  • php password_verify() hash and pass won't match

    1 answer



  • Reference - What does this error mean in PHP?

    31 answers



  • How to display errors for my MySQLi query? [duplicate]

    3 answers




I am trying to create a log in system with session in php with data mysql but for some reason i keep getting the wrong password every time I sign in (putting in username seems to be fine) I think there is something wrong with comparing the user's password in the data but i am not sure what it is...



<?php


if (isset($_POST['login-submit'])) {

require 'db.hide.php';

$mailuserid = $_POST['mailuid'];
$password = $_POST['pwd'];

if (empty($mailuserid) || empty($password)) {
header("Location: ../index.php?error=emptyfields");
exit();
}
else {
$sql = "SELECT * FROM project3 WHERE user=? OR email=?;";
$stmt = mysqli_stmt_init($connect);
if (!mysqli_stmt_prepare($stmt, $sql)) {
header("Location: ../index.php?error=sqlerror");
exit();
}
else {
mysqli_stmt_bind_param($stmt, "ss", $mailuserid, $mailuserid);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
if ($info = mysqli_fetch_assoc($result)) {
$checkPass = password_verify($password, $info['pass']);
if ($checkPass == false) {
header("Location: ../index.php?error=wrongpassword");
exit();
}
elseif ($checkPass == true) {
session_start();
$_SESSION['profileId'] = $info['id'];
$_SESSION['profileUser'] = $info['user'];

header("Location: ../index.php?login=success");
exit();
}
else {
header("Location: ../index.php?error=wrongpassword");
exit();
}
}
else {
header("Location: ../index.php?error=missinguser");
exit();
}
}
}

}
else {
header("Location: ../index.php");
exit();
}


HERE IS THE TABLE:



<?php
require "header.php";
?>
<style>
label {
display: inline-block;
width: 160px;
}
fieldset {
width: 300px;
margin: auto;
}
</style>
<main>
<form action="include/signup.hide.php" method="post">
<fieldset>
<legend><h2>Registration Form</h2></legend>
<label>Username:</label>
<input type="text" name="user"><br>
<span class="error"></span><br><br>

<label>Password:</label>
<input type="password" name="pwd"><br>
<span class="error"></span><br><br>

<label>Email Address:</label>
<input type="text" name="email"><br>
<span class="error"></span><br><br>

<button type="submit" name="button">Signup</button>
</fieldset>
</form>
</main>


CODE FOR SIGNING UP ACCOUNT:



<?php
if (isset($_POST['button'])) {

require 'db.hide.php';

$username = $_POST['user'];
$password = $_POST['pwd'];
$email = $_POST['email'];


if (empty($username) || empty($password) || empty($email)) {
header("Location: ../signup.php?error=emptyfields");
exit();
}
elseif (!filter_var($email, FILTER_VALIDATE_EMAIL) && !preg_match("/^[a-zA-Z0-9]*$/", $username)) {
header("Location: ../signup.php?error=invalidmailuid");
exit();
}
elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
header("Location: ../signup.php?error=invalidmail&uid=".$username);
exit();
}
elseif (!preg_match("/^[a-zA-Z0-9]*$/", $username)) {
header("Location: ../signup.php?error=invaliduid&mail=".$email);
exit();
}
else {
$sql = "INSERT INTO project3 (user, pass, email) VALUES (?, ?, ?)";
$stmt = mysqli_stmt_init($connect);
if (!mysqli_stmt_prepare($stmt, $sql)) {
header("Location: ../signup.php?error=sqlerror");
exit();
}
else {
mysqli_stmt_bind_param($stmt, "sss", $username, $password, $email);
mysqli_stmt_execute($stmt);
header("Location: ../signup.php?signup=success");
exit();
}
}
mysqli_stmt_close($stmt);
mysql_close($connect);
}
else {
header("Location: ../signup.php");
exit();
}









share|improve this question















marked as duplicate by Funk Forty Niner php
Users with the  php badge can single-handedly close php questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 10 at 21:51


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.















  • please show the table def (or lock up how long the field 'pass' is)! And maybe how you safe the pwd-hash.
    – Jeff
    Nov 10 at 21:26












  • Can you please include the details of the error message?
    – dmcgrandle
    Nov 10 at 21:27










  • @dmcgrandle there is no error message I was talking about the error I set header("Location: ../index.php?error=wrongpassword"); I am not getting this when I try logging in header("Location: ../index.php?login=success");
    – IloveCorgis
    Nov 10 at 21:31








  • 1




    you don't password_hash() your password when/before saving it!
    – Jeff
    Nov 10 at 22:02








  • 1




    there's nothing in your shown code that could redirect to "index.php?login=error"
    – Jeff
    Nov 11 at 13:52















up vote
-1
down vote

favorite













This question already has an answer here:




  • php password_verify() hash and pass won't match

    1 answer



  • Reference - What does this error mean in PHP?

    31 answers



  • How to display errors for my MySQLi query? [duplicate]

    3 answers




I am trying to create a log in system with session in php with data mysql but for some reason i keep getting the wrong password every time I sign in (putting in username seems to be fine) I think there is something wrong with comparing the user's password in the data but i am not sure what it is...



<?php


if (isset($_POST['login-submit'])) {

require 'db.hide.php';

$mailuserid = $_POST['mailuid'];
$password = $_POST['pwd'];

if (empty($mailuserid) || empty($password)) {
header("Location: ../index.php?error=emptyfields");
exit();
}
else {
$sql = "SELECT * FROM project3 WHERE user=? OR email=?;";
$stmt = mysqli_stmt_init($connect);
if (!mysqli_stmt_prepare($stmt, $sql)) {
header("Location: ../index.php?error=sqlerror");
exit();
}
else {
mysqli_stmt_bind_param($stmt, "ss", $mailuserid, $mailuserid);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
if ($info = mysqli_fetch_assoc($result)) {
$checkPass = password_verify($password, $info['pass']);
if ($checkPass == false) {
header("Location: ../index.php?error=wrongpassword");
exit();
}
elseif ($checkPass == true) {
session_start();
$_SESSION['profileId'] = $info['id'];
$_SESSION['profileUser'] = $info['user'];

header("Location: ../index.php?login=success");
exit();
}
else {
header("Location: ../index.php?error=wrongpassword");
exit();
}
}
else {
header("Location: ../index.php?error=missinguser");
exit();
}
}
}

}
else {
header("Location: ../index.php");
exit();
}


HERE IS THE TABLE:



<?php
require "header.php";
?>
<style>
label {
display: inline-block;
width: 160px;
}
fieldset {
width: 300px;
margin: auto;
}
</style>
<main>
<form action="include/signup.hide.php" method="post">
<fieldset>
<legend><h2>Registration Form</h2></legend>
<label>Username:</label>
<input type="text" name="user"><br>
<span class="error"></span><br><br>

<label>Password:</label>
<input type="password" name="pwd"><br>
<span class="error"></span><br><br>

<label>Email Address:</label>
<input type="text" name="email"><br>
<span class="error"></span><br><br>

<button type="submit" name="button">Signup</button>
</fieldset>
</form>
</main>


CODE FOR SIGNING UP ACCOUNT:



<?php
if (isset($_POST['button'])) {

require 'db.hide.php';

$username = $_POST['user'];
$password = $_POST['pwd'];
$email = $_POST['email'];


if (empty($username) || empty($password) || empty($email)) {
header("Location: ../signup.php?error=emptyfields");
exit();
}
elseif (!filter_var($email, FILTER_VALIDATE_EMAIL) && !preg_match("/^[a-zA-Z0-9]*$/", $username)) {
header("Location: ../signup.php?error=invalidmailuid");
exit();
}
elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
header("Location: ../signup.php?error=invalidmail&uid=".$username);
exit();
}
elseif (!preg_match("/^[a-zA-Z0-9]*$/", $username)) {
header("Location: ../signup.php?error=invaliduid&mail=".$email);
exit();
}
else {
$sql = "INSERT INTO project3 (user, pass, email) VALUES (?, ?, ?)";
$stmt = mysqli_stmt_init($connect);
if (!mysqli_stmt_prepare($stmt, $sql)) {
header("Location: ../signup.php?error=sqlerror");
exit();
}
else {
mysqli_stmt_bind_param($stmt, "sss", $username, $password, $email);
mysqli_stmt_execute($stmt);
header("Location: ../signup.php?signup=success");
exit();
}
}
mysqli_stmt_close($stmt);
mysql_close($connect);
}
else {
header("Location: ../signup.php");
exit();
}









share|improve this question















marked as duplicate by Funk Forty Niner php
Users with the  php badge can single-handedly close php questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 10 at 21:51


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.















  • please show the table def (or lock up how long the field 'pass' is)! And maybe how you safe the pwd-hash.
    – Jeff
    Nov 10 at 21:26












  • Can you please include the details of the error message?
    – dmcgrandle
    Nov 10 at 21:27










  • @dmcgrandle there is no error message I was talking about the error I set header("Location: ../index.php?error=wrongpassword"); I am not getting this when I try logging in header("Location: ../index.php?login=success");
    – IloveCorgis
    Nov 10 at 21:31








  • 1




    you don't password_hash() your password when/before saving it!
    – Jeff
    Nov 10 at 22:02








  • 1




    there's nothing in your shown code that could redirect to "index.php?login=error"
    – Jeff
    Nov 11 at 13:52













up vote
-1
down vote

favorite









up vote
-1
down vote

favorite












This question already has an answer here:




  • php password_verify() hash and pass won't match

    1 answer



  • Reference - What does this error mean in PHP?

    31 answers



  • How to display errors for my MySQLi query? [duplicate]

    3 answers




I am trying to create a log in system with session in php with data mysql but for some reason i keep getting the wrong password every time I sign in (putting in username seems to be fine) I think there is something wrong with comparing the user's password in the data but i am not sure what it is...



<?php


if (isset($_POST['login-submit'])) {

require 'db.hide.php';

$mailuserid = $_POST['mailuid'];
$password = $_POST['pwd'];

if (empty($mailuserid) || empty($password)) {
header("Location: ../index.php?error=emptyfields");
exit();
}
else {
$sql = "SELECT * FROM project3 WHERE user=? OR email=?;";
$stmt = mysqli_stmt_init($connect);
if (!mysqli_stmt_prepare($stmt, $sql)) {
header("Location: ../index.php?error=sqlerror");
exit();
}
else {
mysqli_stmt_bind_param($stmt, "ss", $mailuserid, $mailuserid);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
if ($info = mysqli_fetch_assoc($result)) {
$checkPass = password_verify($password, $info['pass']);
if ($checkPass == false) {
header("Location: ../index.php?error=wrongpassword");
exit();
}
elseif ($checkPass == true) {
session_start();
$_SESSION['profileId'] = $info['id'];
$_SESSION['profileUser'] = $info['user'];

header("Location: ../index.php?login=success");
exit();
}
else {
header("Location: ../index.php?error=wrongpassword");
exit();
}
}
else {
header("Location: ../index.php?error=missinguser");
exit();
}
}
}

}
else {
header("Location: ../index.php");
exit();
}


HERE IS THE TABLE:



<?php
require "header.php";
?>
<style>
label {
display: inline-block;
width: 160px;
}
fieldset {
width: 300px;
margin: auto;
}
</style>
<main>
<form action="include/signup.hide.php" method="post">
<fieldset>
<legend><h2>Registration Form</h2></legend>
<label>Username:</label>
<input type="text" name="user"><br>
<span class="error"></span><br><br>

<label>Password:</label>
<input type="password" name="pwd"><br>
<span class="error"></span><br><br>

<label>Email Address:</label>
<input type="text" name="email"><br>
<span class="error"></span><br><br>

<button type="submit" name="button">Signup</button>
</fieldset>
</form>
</main>


CODE FOR SIGNING UP ACCOUNT:



<?php
if (isset($_POST['button'])) {

require 'db.hide.php';

$username = $_POST['user'];
$password = $_POST['pwd'];
$email = $_POST['email'];


if (empty($username) || empty($password) || empty($email)) {
header("Location: ../signup.php?error=emptyfields");
exit();
}
elseif (!filter_var($email, FILTER_VALIDATE_EMAIL) && !preg_match("/^[a-zA-Z0-9]*$/", $username)) {
header("Location: ../signup.php?error=invalidmailuid");
exit();
}
elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
header("Location: ../signup.php?error=invalidmail&uid=".$username);
exit();
}
elseif (!preg_match("/^[a-zA-Z0-9]*$/", $username)) {
header("Location: ../signup.php?error=invaliduid&mail=".$email);
exit();
}
else {
$sql = "INSERT INTO project3 (user, pass, email) VALUES (?, ?, ?)";
$stmt = mysqli_stmt_init($connect);
if (!mysqli_stmt_prepare($stmt, $sql)) {
header("Location: ../signup.php?error=sqlerror");
exit();
}
else {
mysqli_stmt_bind_param($stmt, "sss", $username, $password, $email);
mysqli_stmt_execute($stmt);
header("Location: ../signup.php?signup=success");
exit();
}
}
mysqli_stmt_close($stmt);
mysql_close($connect);
}
else {
header("Location: ../signup.php");
exit();
}









share|improve this question
















This question already has an answer here:




  • php password_verify() hash and pass won't match

    1 answer



  • Reference - What does this error mean in PHP?

    31 answers



  • How to display errors for my MySQLi query? [duplicate]

    3 answers




I am trying to create a log in system with session in php with data mysql but for some reason i keep getting the wrong password every time I sign in (putting in username seems to be fine) I think there is something wrong with comparing the user's password in the data but i am not sure what it is...



<?php


if (isset($_POST['login-submit'])) {

require 'db.hide.php';

$mailuserid = $_POST['mailuid'];
$password = $_POST['pwd'];

if (empty($mailuserid) || empty($password)) {
header("Location: ../index.php?error=emptyfields");
exit();
}
else {
$sql = "SELECT * FROM project3 WHERE user=? OR email=?;";
$stmt = mysqli_stmt_init($connect);
if (!mysqli_stmt_prepare($stmt, $sql)) {
header("Location: ../index.php?error=sqlerror");
exit();
}
else {
mysqli_stmt_bind_param($stmt, "ss", $mailuserid, $mailuserid);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
if ($info = mysqli_fetch_assoc($result)) {
$checkPass = password_verify($password, $info['pass']);
if ($checkPass == false) {
header("Location: ../index.php?error=wrongpassword");
exit();
}
elseif ($checkPass == true) {
session_start();
$_SESSION['profileId'] = $info['id'];
$_SESSION['profileUser'] = $info['user'];

header("Location: ../index.php?login=success");
exit();
}
else {
header("Location: ../index.php?error=wrongpassword");
exit();
}
}
else {
header("Location: ../index.php?error=missinguser");
exit();
}
}
}

}
else {
header("Location: ../index.php");
exit();
}


HERE IS THE TABLE:



<?php
require "header.php";
?>
<style>
label {
display: inline-block;
width: 160px;
}
fieldset {
width: 300px;
margin: auto;
}
</style>
<main>
<form action="include/signup.hide.php" method="post">
<fieldset>
<legend><h2>Registration Form</h2></legend>
<label>Username:</label>
<input type="text" name="user"><br>
<span class="error"></span><br><br>

<label>Password:</label>
<input type="password" name="pwd"><br>
<span class="error"></span><br><br>

<label>Email Address:</label>
<input type="text" name="email"><br>
<span class="error"></span><br><br>

<button type="submit" name="button">Signup</button>
</fieldset>
</form>
</main>


CODE FOR SIGNING UP ACCOUNT:



<?php
if (isset($_POST['button'])) {

require 'db.hide.php';

$username = $_POST['user'];
$password = $_POST['pwd'];
$email = $_POST['email'];


if (empty($username) || empty($password) || empty($email)) {
header("Location: ../signup.php?error=emptyfields");
exit();
}
elseif (!filter_var($email, FILTER_VALIDATE_EMAIL) && !preg_match("/^[a-zA-Z0-9]*$/", $username)) {
header("Location: ../signup.php?error=invalidmailuid");
exit();
}
elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
header("Location: ../signup.php?error=invalidmail&uid=".$username);
exit();
}
elseif (!preg_match("/^[a-zA-Z0-9]*$/", $username)) {
header("Location: ../signup.php?error=invaliduid&mail=".$email);
exit();
}
else {
$sql = "INSERT INTO project3 (user, pass, email) VALUES (?, ?, ?)";
$stmt = mysqli_stmt_init($connect);
if (!mysqli_stmt_prepare($stmt, $sql)) {
header("Location: ../signup.php?error=sqlerror");
exit();
}
else {
mysqli_stmt_bind_param($stmt, "sss", $username, $password, $email);
mysqli_stmt_execute($stmt);
header("Location: ../signup.php?signup=success");
exit();
}
}
mysqli_stmt_close($stmt);
mysql_close($connect);
}
else {
header("Location: ../signup.php");
exit();
}




This question already has an answer here:




  • php password_verify() hash and pass won't match

    1 answer



  • Reference - What does this error mean in PHP?

    31 answers



  • How to display errors for my MySQLi query? [duplicate]

    3 answers








php passwords






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 10 at 22:04









Jeff

5,89011024




5,89011024










asked Nov 10 at 21:24









IloveCorgis

14




14




marked as duplicate by Funk Forty Niner php
Users with the  php badge can single-handedly close php questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 10 at 21:51


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






marked as duplicate by Funk Forty Niner php
Users with the  php badge can single-handedly close php questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 10 at 21:51


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • please show the table def (or lock up how long the field 'pass' is)! And maybe how you safe the pwd-hash.
    – Jeff
    Nov 10 at 21:26












  • Can you please include the details of the error message?
    – dmcgrandle
    Nov 10 at 21:27










  • @dmcgrandle there is no error message I was talking about the error I set header("Location: ../index.php?error=wrongpassword"); I am not getting this when I try logging in header("Location: ../index.php?login=success");
    – IloveCorgis
    Nov 10 at 21:31








  • 1




    you don't password_hash() your password when/before saving it!
    – Jeff
    Nov 10 at 22:02








  • 1




    there's nothing in your shown code that could redirect to "index.php?login=error"
    – Jeff
    Nov 11 at 13:52


















  • please show the table def (or lock up how long the field 'pass' is)! And maybe how you safe the pwd-hash.
    – Jeff
    Nov 10 at 21:26












  • Can you please include the details of the error message?
    – dmcgrandle
    Nov 10 at 21:27










  • @dmcgrandle there is no error message I was talking about the error I set header("Location: ../index.php?error=wrongpassword"); I am not getting this when I try logging in header("Location: ../index.php?login=success");
    – IloveCorgis
    Nov 10 at 21:31








  • 1




    you don't password_hash() your password when/before saving it!
    – Jeff
    Nov 10 at 22:02








  • 1




    there's nothing in your shown code that could redirect to "index.php?login=error"
    – Jeff
    Nov 11 at 13:52
















please show the table def (or lock up how long the field 'pass' is)! And maybe how you safe the pwd-hash.
– Jeff
Nov 10 at 21:26






please show the table def (or lock up how long the field 'pass' is)! And maybe how you safe the pwd-hash.
– Jeff
Nov 10 at 21:26














Can you please include the details of the error message?
– dmcgrandle
Nov 10 at 21:27




Can you please include the details of the error message?
– dmcgrandle
Nov 10 at 21:27












@dmcgrandle there is no error message I was talking about the error I set header("Location: ../index.php?error=wrongpassword"); I am not getting this when I try logging in header("Location: ../index.php?login=success");
– IloveCorgis
Nov 10 at 21:31






@dmcgrandle there is no error message I was talking about the error I set header("Location: ../index.php?error=wrongpassword"); I am not getting this when I try logging in header("Location: ../index.php?login=success");
– IloveCorgis
Nov 10 at 21:31






1




1




you don't password_hash() your password when/before saving it!
– Jeff
Nov 10 at 22:02






you don't password_hash() your password when/before saving it!
– Jeff
Nov 10 at 22:02






1




1




there's nothing in your shown code that could redirect to "index.php?login=error"
– Jeff
Nov 11 at 13:52




there's nothing in your shown code that could redirect to "index.php?login=error"
– Jeff
Nov 11 at 13:52

















active

oldest

votes






















active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes

Popular posts from this blog

App crashed after uploaded to heroku server

Thiostrepton

Jo Brand