title: Password hash in php registration and login not working
body: <p>I'm using password salt to hash users' password during registration, also use the same method in login but it always show me incorrect password please can someone tell me what is the error.
  If i remove the password salt it will work fine but i need to secure the password.</p>
  
  <p><strong>Here is my registration code</strong></p>
  
  <pre><code>&lt;?php
  
  include($root . 'database_connection.php');
  if (isset($_POST['formsubmitted'])) {
    $username = $_POST['username']; //else assign it a variable
    $email = $_POST['email'];
    $password = $_POST['password'];
  
          $salt = "@g26jQsG&amp;nh*&amp;#8v";
          $passcode =  sha1($password.$salt);
          $name = $username;
          $pass = $passcode;
          $mail = $email;
          $query_insert_user = "INSERT INTO `users` ( `username`, `password`, `email`, `active`) VALUES ( '$name', '$pass', '$mail', '$numbers')";
  
              $result_insert_user = mysqli_query($db_conn, $query_insert_user);
              if (!$result_insert_user) {
                  echo 'Query Failed ';
              }   
  
      mysqli_close($db_conn); //Close the DB Connection
  
  } // End of the main Submit conditional.
  
  ?&gt;
  </code></pre>
  
  <p><strong>Login page</strong></p>
  
  <pre><code> &lt;?php
  
          if ($_POST) {
  
            $salt = "@g26jQsG&amp;nh*&amp;#8v";
            $password =  sha1($_POST['password'].$salt);
  
            $logdb = new PDO('mysql:host=localhost;dbname=userdb', 'root', 'pass');
            $logdb-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
            $stmt = $logdb-&gt;prepare("SELECT * FROM users WHERE username=:username AND password=:password");
            $stmt-&gt;bindParam(":username", $_POST['username']);
            $stmt-&gt;bindParam(":password", $password);
            $stmt-&gt;execute();
  
          $atributes = $stmt-&gt;fetch(PDO::FETCH_OBJ);
          if ($atributes) {
              session_start();
  
               $username  = $atributes-&gt;username;
               $_SESSION['username'] = $username;
               $active = $atributes-&gt;active;
               $email = $atributes-&gt;email;
      if($active==0){
      echo '&lt;table&gt;&lt;td width="50px" valign="top"&gt;&lt;i class="fa fa-ban mail2"&gt;&lt;/i&gt;&lt;/td&gt;&lt;td&gt;&lt;div&gt;Authentication Error! Your account is not verified please verify your email.&lt;br/&gt;
      &lt;small&gt;Need more help? Please contact the systems administrator.&lt;/small&gt;&lt;/div&gt;&lt;/td&gt;&lt;/table&gt;';}
      else{
              header("location: index.php");
      } 
  
            } else {
               header("location: login.php?else=0&amp;n");
                //incorrect
              }
  
          }   
  
             else {
           header("location: login.php?false=1&amp;n");
                echo '&lt;form name="login" action="" method="POST"&gt;
            Username: &lt;br /&gt;
            &lt;input type="text" name="username"/&gt;&lt;br /&gt;
            Password: &lt;br /&gt;
            &lt;input type="password" name="password"/&gt;&lt;br /&gt;
            &lt;button type="submit"&gt;Login&lt;/button&gt;
            &lt;a href="signup.php"&gt;Register&lt;/a&gt;&lt;/form&gt;';
  
  
            }
          $logdb=null;
      ?&gt;
  </code></pre>