title: PHP comparing values received from java
body: <p>so I'm working on this 2 PHP Files, <code>login.php</code> and <code>DB_Functions.php</code></p>
  
  <p>there is a specific script in there that is receiving a password and email from the application finding that specific user using the given email and store all the user details in a <code>$user</code> array and pass it over to login.php that check if the password entered is correct or not, i've tried hash'ing the password since on the DB its encrypted with 64 BIT.</p>
  
  <p>this is <code>login.php</code> (the problem is probably in the <code>if($user[7] == $password)</code> which isn't working).</p>
  
  <pre><code> &lt;?php
  require_once 'include/DB_Functions.php';
  $db = new DB_Functions();
  
  // json response array
  $response = array("error" =&gt; FALSE);
  
  if (isset($_POST['email']) &amp;&amp; isset($_POST['password'])) {
  
      // receiving the post params
      $email = $_POST['email'];
      $password = $_POST['password'];
  
      // get the user by email and password
      $user = $db-&gt;getUserByEmailAndPassword($email, $password);
  
      if ($user != false) {
  
  if($user[7] == $password){
  // user is found
  $response["error"] = FALSE;
  $response["uid"] = $user[0];
  $response["user"]["name"] = $user[1];
  $response["user"]["email"] = $user[2];
  $response["user"]["created_at"] = $user[3];
  $response["user"]["updated_at"] = $user[4];
  echo json_encode($response);
  }else {
  
  // user is not found with the credentials
  $response["error"] = TRUE;
  $response["error_msg"] = "Login password credentials are wrong. Please try again!".$checkkk;
  echo json_encode($response);
  }} else {
  // user is not found with the credentials
  $response["error"] = TRUE;
  $response["error_msg"] = "Login credentials are wrong. Please try again!";
  echo json_encode($response);
  }
  }
  ?&gt;
  </code></pre>
  
  <p>this is the <code>DB_Function.php</code> file ill add only the corresponding functions.</p>
  
  <pre><code>/**
   * Get user by email and password
   */
  public function getUserByEmailAndPassword($email, $password) {
  
      $stmt = $this-&gt;conn-&gt;prepare("SELECT unique_id,name,email,created_at,updated_at, encrypted_password , salt FROM users WHERE email = ?");
  
      $stmt-&gt;bind_param("s", $email);
  
      if ($stmt-&gt;execute()) {
              $stmt-&gt;store_result();
              $num_of_rows = $stmt-&gt;num_rows;
              $stmt-&gt;bind_result($aid, $aname, $aemail, $acreated_at, $aupdated_at , $aencrypted_password , $asalt);
  
                      while ($stmt-&gt;fetch()) {
                      $user[0] = $aid;
                      $user[1] = $aname;
                      $user[2] = $aemail;
                      $user[3] = $acreated_at;
                      $user[4] = $aupdated_at;
                      $user[5] = $aencrypted_password;
                      $user[6] = $asalt;
                      $user[7] = $this-&gt;checkhashSSHA($asalt, $password);
                      }
              $stmt-&gt;free_result();
              $stmt-&gt;close();
              return $user;
              } else {
              return NULL;
              }
      }
  
  /**
   * Check user is existed or not
   */
  public function isUserExisted($email) {
      $stmt = $this-&gt;conn-&gt;prepare("SELECT email from users WHERE email = ?");
  
      $stmt-&gt;bind_param("s", $email);
  
      $stmt-&gt;execute();
  
      $stmt-&gt;store_result();
  
      if ($stmt-&gt;num_rows &gt; 0) {
          // user exists
          $stmt-&gt;close();
          return true;
      } else {
          // user not exists
          $stmt-&gt;close();
          return false;
      }
  }
  
  /**
   * Encrypting password
   * @param password
   * returns salt and encrypted password
   */
  public function hashSSHA($password) {
  
      $salt = sha1(rand());
      $salt = substr($salt, 0, 10);
      $encrypted = base64_encode(sha1($password . $salt, true) . $salt);
      $hash = array("salt" =&gt; $salt, "encrypted" =&gt; $encrypted);
      return $hash;
  }
  
  /**
   * Decrypting password
   * @param salt, password
   * returns hash string
   */
  public function checkhashSSHA($salt, $password) {
  
      $hash = base64_encode(sha1($password . $salt, true) . $salt);
  
      return $hash;
  }
  
  
  }
  
  ?&gt;
  </code></pre>
  
  <p>I'm assuming that the problem is at <code>$user[7] = $this-&gt;checkhashSSHA($asalt, $password);</code> line. 
  looking forward for a solution.</p>