Click here to Skip to main content
15,440,884 members
Home / Discussions / Linux, Apache, MySQL, PHP
   

Linux, Apache, MySQL, PHP

 
QuestionHow to make data entered on a form that has not been submitted into MySql database appear on another form Pin
Member 1369186126-Apr-18 5:22
MemberMember 1369186126-Apr-18 5:22 
QuestionHow to use 4 digit incremental serial number on mysql database using PHP on my form Pin
Member 1369186126-Apr-18 2:16
MemberMember 1369186126-Apr-18 2:16 
AnswerRe: How to use 4 digit incremental serial number on mysql database using PHP on my form Pin
Jochen Arndt26-Apr-18 2:31
professionalJochen Arndt26-Apr-18 2:31 
GeneralRe: How to use 4 digit incremental serial number on mysql database using PHP on my form Pin
Member 1369186126-Apr-18 2:42
MemberMember 1369186126-Apr-18 2:42 
QuestionHow to use PHP global processing script action to process sumbitted data and display form data entered on the text on another page Pin
Member 1369186126-Apr-18 2:13
MemberMember 1369186126-Apr-18 2:13 
AnswerRe: How to use PHP global processing script action to process sumbitted data and display form data entered on the text on another page Pin
Richard MacCutchan26-Apr-18 2:49
mveRichard MacCutchan26-Apr-18 2:49 
QuestionHow to use a php $_SERVER['PHP_SELF'] to insert form data into Mysql database and redisplay data entered on another form Pin
Member 1369186126-Apr-18 2:11
MemberMember 1369186126-Apr-18 2:11 
QuestionPassword Verify Pin
Valecia_cho30-Mar-18 13:32
MemberValecia_cho30-Mar-18 13:32 
So I'm building a website and I've got alot of the core functionality sorted. Been trying to make a register and login system. Everything on the front end works ok. Registering is fine but I can't get the password_verify function to recognise a correct password.

So here's the registration part:

PHP
$res = $conn->query("SELECT * FROM `users` WHERE `email`= '$email'");

if (mysqli_num_rows($res) != 0) {
  echo "<br>  Sorry this email already is registered with us!!!  <br>";
  $start = microtime(true);
  do {
    $stop = microtime(true);
  } while ($stop - $start < 5);
  header("location: index.php");
}
else {
  // Password hashing
  $cost = 8;
  $target_time = 0.05;
  // When microtime is set to true it returns a float
  // If set to false then returns a string

  do {
    $start = microtime(true);
    $password = password_hash( $password, PASSWORD_BCRYPT, ["cost" => $cost] );
    $stop = microtime(true);
    $cost++;

  } while ($stop - $start < $target_time);


  $date = date("Y-m-d ");

  $sql="INSERT INTO `users` (`username`, `email`, `password`, `sign_up_date`)
  VALUES ('$username', '$email', '$password', '$date')";

  if ($conn->query($sql)) {
    echo "Registration Successful!!!";
    header( "location: index.php" );
  }

}


That's just the part where a hash is generated and stored on an SQL database. Now here's the login part:

$conn = new mysqli( "localhost", $user, $pass, $db ) or die("Unable to connect");

$email = mysqli_real_escape_string($conn, $_POST['email']);

$res = $conn->query("SELECT * FROM `users` WHERE `email`= '$email'");

if (mysqli_num_rows($res) == false) {
  echo "Sorry no such user exists :(";
}
else {
  $user = $res->fetch_assoc();

  if ( password_verify(  $_POST['password'], $user['password']) ) {
    echo " Password login accepted. Redirecting...";
    $_SESSION['username'] = $user['username'];
    $_SESSION['email'] = $user['email'];

    $_SESSION['logged_in'] = true;
    header("location: testFront.php");
  }
  else {
    echo "<br>Sorry Wrong Password!!!<br>";
  }

}


For some reason the password_verify keeps returning false and I have no idea why. Have I overlooked something in the code. Is it my fundamental understanding of hashes?

Thanks
QuestionHow to call a reply forms using php. Pin
Member 1370467720-Mar-18 20:45
MemberMember 1370467720-Mar-18 20:45 
Questiondynamic question in php and mysql Pin
antonio_dsanchez9-Feb-18 10:24
Memberantonio_dsanchez9-Feb-18 10:24 
QuestionGet the html content from a website using php Pin
Joshin Joy17-Dec-17 20:51
MemberJoshin Joy17-Dec-17 20:51 
AnswerRe: Get the html content from a website using php Pin
Jochen Arndt17-Dec-17 22:38
professionalJochen Arndt17-Dec-17 22:38 
GeneralRe: Get the html content from a website using php Pin
Joshin Joy18-Dec-17 20:15
MemberJoshin Joy18-Dec-17 20:15 
GeneralRe: Get the html content from a website using php Pin
Jochen Arndt18-Dec-17 21:02
professionalJochen Arndt18-Dec-17 21:02 
GeneralRe: Get the html content from a website using php Pin
Member 1387615717-Jun-18 20:01
MemberMember 1387615717-Jun-18 20:01 
Questionfunction to display content with php does not work as intended Pin
CHrispho15-Dec-17 9:46
MemberCHrispho15-Dec-17 9:46 
AnswerRe: function to display content with php does not work as intended Pin
Jochen Arndt17-Dec-17 22:50
professionalJochen Arndt17-Dec-17 22:50 
QuestionChat functionality is not working when SSL is involved Pin
Member 135528281-Dec-17 17:15
MemberMember 135528281-Dec-17 17:15 
AnswerRe: Chat functionality is not working when SSL is involved Pin
jschell5-Dec-17 12:29
Memberjschell5-Dec-17 12:29 
QuestionPHP: using Facebook login SDK returned an error: No URL set! Pin
iucaa19-Nov-17 22:53
Memberiucaa19-Nov-17 22:53 
QuestionPHP Getting Data From Javascript Pin
Valecia_cho23-Oct-17 13:48
MemberValecia_cho23-Oct-17 13:48 
AnswerRe: PHP Getting Data From Javascript Pin
Richard Deeming24-Oct-17 2:08
mveRichard Deeming24-Oct-17 2:08 
QuestionHow do I Attach acrobat pdf page to email in codeigniter? Pin
Member 1347022217-Oct-17 4:13
MemberMember 1347022217-Oct-17 4:13 
SuggestionRe: TLDR Pin
Richard Deeming17-Oct-17 4:31
mveRichard Deeming17-Oct-17 4:31 
QuestionThinkphp 5.0 query table how the array of how to get rid of a column? And then save it to another table? Pin
micccn13-Oct-17 23:37
Membermicccn13-Oct-17 23:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.