Password invalid using password_verify and password_hash [duplicate]
This question already has an answer here:
Using password_hash and password_verify
1 answer
“Notice: Undefined variable”, “Notice: Undefined index”, and “Notice: Undefined offset” using PHP
28 answers
I am writing a login page. The password stored in my database is encrypted using password_hash. When I'm trying to compare between the entered password and the stored password, they don't match.
This is my form:
<input type="text" class="form-control" id="inlineFormInput" placeholder="Jane Doe" name="username" required>
<input type="password" class="form-control" id="exampleInputPassword1" placeholder="Password" name="password" required>
...and this is my PHP code:
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "lab2";
if($dbc=@mysqli_connect($servername,$username,$password,$dbname)){
print "connected";
print "<br>";
$q = "select * from users where username = '". $_POST['username'] ."'
";
if($result=@mysqli_query($dbc,$q)){
$row = mysqli_fetch_array($result);
if(password_verify($_POST['password'],$row['password'])){
print "you are logged in!";
print "<br>";
}else {
print "username or password error";
//header('Refresh: 2;login.php');
}
}else{
print "error occured: ";
print mysqli_error($dbc);
}
}else {
print "connection error: ";
print mysqli_connect_error();
}
?>
this is how I created the hashed password
$password = $_POST['password'];
$hashed_password = password_hash($password, PASSWORD_DEFAULT);
$q = "insert into users (username,email,password,date)
values ('".$_POST['username']."','".$_POST['email']."','$hashed_password','$date')
";
php mysql forms passwords
marked as duplicate by Funk Forty Niner
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 13 '18 at 23:32
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.
|
show 15 more comments
This question already has an answer here:
Using password_hash and password_verify
1 answer
“Notice: Undefined variable”, “Notice: Undefined index”, and “Notice: Undefined offset” using PHP
28 answers
I am writing a login page. The password stored in my database is encrypted using password_hash. When I'm trying to compare between the entered password and the stored password, they don't match.
This is my form:
<input type="text" class="form-control" id="inlineFormInput" placeholder="Jane Doe" name="username" required>
<input type="password" class="form-control" id="exampleInputPassword1" placeholder="Password" name="password" required>
...and this is my PHP code:
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "lab2";
if($dbc=@mysqli_connect($servername,$username,$password,$dbname)){
print "connected";
print "<br>";
$q = "select * from users where username = '". $_POST['username'] ."'
";
if($result=@mysqli_query($dbc,$q)){
$row = mysqli_fetch_array($result);
if(password_verify($_POST['password'],$row['password'])){
print "you are logged in!";
print "<br>";
}else {
print "username or password error";
//header('Refresh: 2;login.php');
}
}else{
print "error occured: ";
print mysqli_error($dbc);
}
}else {
print "connection error: ";
print mysqli_connect_error();
}
?>
this is how I created the hashed password
$password = $_POST['password'];
$hashed_password = password_hash($password, PASSWORD_DEFAULT);
$q = "insert into users (username,email,password,date)
values ('".$_POST['username']."','".$_POST['email']."','$hashed_password','$date')
";
php mysql forms passwords
marked as duplicate by Funk Forty Niner
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 13 '18 at 23:32
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.
1
Please edit your question to include the source code how you create the password hash and store it in the database. Also, include theCREATE TABLE
statement of your users table, the password column might not be big enough for the hash to store.
– Progman
Nov 13 '18 at 23:27
1
what is the password column's length? I'm betting it's not long enough to accomodate the (full) hash.
– Funk Forty Niner
Nov 13 '18 at 23:27
1
Seeing the above comment; I added another duplicate. Enable error reporting.
– Funk Forty Niner
Nov 13 '18 at 23:33
1
Please use a prepared statement; you're open to sql injection.
– Funk Forty Niner
Nov 13 '18 at 23:33
1
Didn't get what?
– Funk Forty Niner
Nov 13 '18 at 23:35
|
show 15 more comments
This question already has an answer here:
Using password_hash and password_verify
1 answer
“Notice: Undefined variable”, “Notice: Undefined index”, and “Notice: Undefined offset” using PHP
28 answers
I am writing a login page. The password stored in my database is encrypted using password_hash. When I'm trying to compare between the entered password and the stored password, they don't match.
This is my form:
<input type="text" class="form-control" id="inlineFormInput" placeholder="Jane Doe" name="username" required>
<input type="password" class="form-control" id="exampleInputPassword1" placeholder="Password" name="password" required>
...and this is my PHP code:
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "lab2";
if($dbc=@mysqli_connect($servername,$username,$password,$dbname)){
print "connected";
print "<br>";
$q = "select * from users where username = '". $_POST['username'] ."'
";
if($result=@mysqli_query($dbc,$q)){
$row = mysqli_fetch_array($result);
if(password_verify($_POST['password'],$row['password'])){
print "you are logged in!";
print "<br>";
}else {
print "username or password error";
//header('Refresh: 2;login.php');
}
}else{
print "error occured: ";
print mysqli_error($dbc);
}
}else {
print "connection error: ";
print mysqli_connect_error();
}
?>
this is how I created the hashed password
$password = $_POST['password'];
$hashed_password = password_hash($password, PASSWORD_DEFAULT);
$q = "insert into users (username,email,password,date)
values ('".$_POST['username']."','".$_POST['email']."','$hashed_password','$date')
";
php mysql forms passwords
This question already has an answer here:
Using password_hash and password_verify
1 answer
“Notice: Undefined variable”, “Notice: Undefined index”, and “Notice: Undefined offset” using PHP
28 answers
I am writing a login page. The password stored in my database is encrypted using password_hash. When I'm trying to compare between the entered password and the stored password, they don't match.
This is my form:
<input type="text" class="form-control" id="inlineFormInput" placeholder="Jane Doe" name="username" required>
<input type="password" class="form-control" id="exampleInputPassword1" placeholder="Password" name="password" required>
...and this is my PHP code:
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "lab2";
if($dbc=@mysqli_connect($servername,$username,$password,$dbname)){
print "connected";
print "<br>";
$q = "select * from users where username = '". $_POST['username'] ."'
";
if($result=@mysqli_query($dbc,$q)){
$row = mysqli_fetch_array($result);
if(password_verify($_POST['password'],$row['password'])){
print "you are logged in!";
print "<br>";
}else {
print "username or password error";
//header('Refresh: 2;login.php');
}
}else{
print "error occured: ";
print mysqli_error($dbc);
}
}else {
print "connection error: ";
print mysqli_connect_error();
}
?>
this is how I created the hashed password
$password = $_POST['password'];
$hashed_password = password_hash($password, PASSWORD_DEFAULT);
$q = "insert into users (username,email,password,date)
values ('".$_POST['username']."','".$_POST['email']."','$hashed_password','$date')
";
This question already has an answer here:
Using password_hash and password_verify
1 answer
“Notice: Undefined variable”, “Notice: Undefined index”, and “Notice: Undefined offset” using PHP
28 answers
php mysql forms passwords
php mysql forms passwords
edited Nov 13 '18 at 23:31
aftermath
asked Nov 13 '18 at 23:25
aftermathaftermath
165
165
marked as duplicate by Funk Forty Niner
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 13 '18 at 23:32
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
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 13 '18 at 23:32
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.
1
Please edit your question to include the source code how you create the password hash and store it in the database. Also, include theCREATE TABLE
statement of your users table, the password column might not be big enough for the hash to store.
– Progman
Nov 13 '18 at 23:27
1
what is the password column's length? I'm betting it's not long enough to accomodate the (full) hash.
– Funk Forty Niner
Nov 13 '18 at 23:27
1
Seeing the above comment; I added another duplicate. Enable error reporting.
– Funk Forty Niner
Nov 13 '18 at 23:33
1
Please use a prepared statement; you're open to sql injection.
– Funk Forty Niner
Nov 13 '18 at 23:33
1
Didn't get what?
– Funk Forty Niner
Nov 13 '18 at 23:35
|
show 15 more comments
1
Please edit your question to include the source code how you create the password hash and store it in the database. Also, include theCREATE TABLE
statement of your users table, the password column might not be big enough for the hash to store.
– Progman
Nov 13 '18 at 23:27
1
what is the password column's length? I'm betting it's not long enough to accomodate the (full) hash.
– Funk Forty Niner
Nov 13 '18 at 23:27
1
Seeing the above comment; I added another duplicate. Enable error reporting.
– Funk Forty Niner
Nov 13 '18 at 23:33
1
Please use a prepared statement; you're open to sql injection.
– Funk Forty Niner
Nov 13 '18 at 23:33
1
Didn't get what?
– Funk Forty Niner
Nov 13 '18 at 23:35
1
1
Please edit your question to include the source code how you create the password hash and store it in the database. Also, include the
CREATE TABLE
statement of your users table, the password column might not be big enough for the hash to store.– Progman
Nov 13 '18 at 23:27
Please edit your question to include the source code how you create the password hash and store it in the database. Also, include the
CREATE TABLE
statement of your users table, the password column might not be big enough for the hash to store.– Progman
Nov 13 '18 at 23:27
1
1
what is the password column's length? I'm betting it's not long enough to accomodate the (full) hash.
– Funk Forty Niner
Nov 13 '18 at 23:27
what is the password column's length? I'm betting it's not long enough to accomodate the (full) hash.
– Funk Forty Niner
Nov 13 '18 at 23:27
1
1
Seeing the above comment; I added another duplicate. Enable error reporting.
– Funk Forty Niner
Nov 13 '18 at 23:33
Seeing the above comment; I added another duplicate. Enable error reporting.
– Funk Forty Niner
Nov 13 '18 at 23:33
1
1
Please use a prepared statement; you're open to sql injection.
– Funk Forty Niner
Nov 13 '18 at 23:33
Please use a prepared statement; you're open to sql injection.
– Funk Forty Niner
Nov 13 '18 at 23:33
1
1
Didn't get what?
– Funk Forty Niner
Nov 13 '18 at 23:35
Didn't get what?
– Funk Forty Niner
Nov 13 '18 at 23:35
|
show 15 more comments
0
active
oldest
votes
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
1
Please edit your question to include the source code how you create the password hash and store it in the database. Also, include the
CREATE TABLE
statement of your users table, the password column might not be big enough for the hash to store.– Progman
Nov 13 '18 at 23:27
1
what is the password column's length? I'm betting it's not long enough to accomodate the (full) hash.
– Funk Forty Niner
Nov 13 '18 at 23:27
1
Seeing the above comment; I added another duplicate. Enable error reporting.
– Funk Forty Niner
Nov 13 '18 at 23:33
1
Please use a prepared statement; you're open to sql injection.
– Funk Forty Niner
Nov 13 '18 at 23:33
1
Didn't get what?
– Funk Forty Niner
Nov 13 '18 at 23:35