This is a simple login script using Bcrypt. Is there anything wrong with this code? It works and my page loads O.K, but could this be optimized for better speeds?

<!Doctype html>
    <title>password validation</title>



    <form action =passing.php method = "post">


    <td>Email:</td><td><input type="id" name ="id" /><br /></td>

     <td>Password:</td><td><input type = "password" name="password" />  <br /></td>

    <input type = "submit" name ="submit" value ="insert" />
     <br />

     // connect to the server

    $conn = new mysqli('localhost', 'root', '', 'social');

     // check connection
    if(mysqli_connect_errno()) {
        exit("connection failed" . mysqli_connect_error());
      }    else {
       echo "connection established";

if($_POST && isset($_POST['submit'], $_POST['password'],       $_POST['id'])) {

    $pass = ($_POST["password"]);
    $userName = ($conn, $_POST["id"]);
    $input = $pass; //Is this wrong to do?

    $query = mysqli_prepare($conn, "SELECT pass FROM social
    WHERE  email = ?"); //is this query safe?

    mysqli_stmt_bind_param($query,'s', $userName );

        mysqli_stmt_bind_result($query, $userName);

if(mysqli_stmt_fetch($query)) {

    echo "<br />";
    echo "SUCCESS at query";

if (password_verify($input, $userName)) {
    echo "matching pass" . header("Location: inserh.php");
   }  else{
     echo "not a  match";



mysqli_close($conn); // close the connection!!!!!!!!!!!!!
  • 1
    \$\begingroup\$ Welcome to Code Review! Please edit your question title to describe what the code does, on this site we all want to make our code better so there is no need to ask for that. \$\endgroup\$ – Phrancis Apr 7 '16 at 16:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.