title: password hashing for login solution with PHP and javaScript
body: <p>I know that, for security reasons, it is necessary to hash (with salt) the user's password and comparing it to a stored hashed password, so if anybody else gets the hashed string, he will have no way to compute back the password or look it up in a rainbow table.</p>
  
  <p>There is one part of the method that I don't understand. Let's say I have this standard login form</p>
  
  <pre><code>&lt;form method='post' action='login.php'&gt;
      &lt;input type='text' name='user' /&gt;
      &lt;input type='password' name='password' /&gt;
      &lt;input type='submit' name='submit' value='login' /&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>and then I use PHP for login</p>
  
  <pre><code>&lt;?php
      if(isset($_POST['submit'])){
          $username = $_POST['username'];
          $password = sha1($_POST['password']);
          $authorize = $login_object-&gt;login($username, $password);
      }
  ?&gt;
  </code></pre>
  
  <p>and, behind the scenes, the <code>$login_object</code> takes care of authenticating with the database and returning true/false. (I made this object up, I have real, useful objects to do this)</p>
  
  <p>but that means the password in the <code>POST request</code> traveled raw, un-hashed and unsafely! Anybody could have intercepted the real password! </p>
  
  <p>So what I am thinking is that I should use javascript to hash the password before it's sent. I would have a hidden field <code>&lt;input type='hidden' name='real_password' value='' /&gt;</code> and have javaScript copy the value of the input named password, hash it, put it in real_password hidden input and blank the password field. This way, the <code>POST request</code> would have the hashed password and not the raw, unsafe, original password.</p>
  
  <p>Am I right with what I'm saying, or should I just do the hashing on php?</p>