title: different value when retrieving data from database
body: <p>i am a beginner in PHP &amp; MySQL development, I am following a tutorial. I am trying to make login system, after inserting data to Mysql in registration. I want to validate the password from the database and the password from user in login page, if it is match, then login is successful.</p>
  
  <p>here is the password from the database, as we can see, for username=admin the password is <strong>3462623</strong>.....<a href="https://i.stack.imgur.com/Xa61Y.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Xa61Y.png" alt="enter image description here"></a></p>
  
  <p>The data type of this database is like this</p>
  
  <p><a href="https://i.stack.imgur.com/iUW2f.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/iUW2f.png" alt="enter image description here"></a></p>
  
  <p>as we can see, the data type for password and salt is Binary.</p>
  
  <p>when I tried to var_dump the variable which stores the value from the database, the password and salt is different from what appears in the database.</p>
  
  <p>the password should be : <strong>3462623</strong>.....
  but from var_dump, the password is : <strong>4bb5d8229634bf5 .....</strong></p>
  
  <p>other data like id,username,email are correct. just password and salt are different.</p>
  
  <p><a href="https://i.stack.imgur.com/QI1b5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QI1b5.png" alt="enter image description here"></a></p>
  
  <p>I suspect this is because the return value data type from var_dump is String, but when i stored to database, the datatype is Binary, how do I fix that ? it seems that from tutorial I saw, the login system still OK even though the password in string data type.</p>
  
  <p>to be honest I don't understand why it has to be Binary data type. but I guess it because it will be encrypted.</p>
  
  <p>so what went wrong in here?</p>
  
  <p>here is the code :</p>
  
  <p>Registration Process</p>
  
  <pre><code>$username = htmlentities($_REQUEST["username"]);
  $password = htmlentities($_REQUEST["password"]);
  $fullname = htmlentities($_REQUEST["fullname"]);
  $email = htmlentities($_REQUEST["email"]);
  
  if (empty($username) || empty($password) || empty($fullname) || empty($email)) {
  
      $returnArray = [
          "status" =&gt; "400",
          "message" =&gt; "missing required information"
      ];
  
      echo json_encode($returnArray);
      return;
  }
  
  
  
  //encrypt the password
  $salt=openssl_random_pseudo_bytes(20); 
  $securedPassword = sha1($password.$salt);
  
  
  
  // Create Connection
  $file = parse_ini_file("../../../twitter.ini");
  $dbhost = trim($file["host"]); 
  $dbusername = trim($file["username"]);
  $dbpassword = trim($file["password"]);
  $dbname = trim($file["dbname"]);
  
  
  $access = new access($dbhost,$dbusername,$dbpassword,$dbname);
  $access-&gt;connect();
  
  function registerUser($username,$password,$salt,$email,$fullname) {
  
          $query = "INSERT INTO users SET username=?, password=?,salt=?,email=?,fullname=?";
          $statement = $this-&gt;conn-&gt;prepare($query);
  
          if (!$statement) {
              throw new Exception($statement-&gt;error);
          }
  
          $statement-&gt; bind_param('sssss',$username,$password,$salt,$email,$fullname);
          $returnValue = $statement -&gt; execute();
  
  
          return $returnValue;
      }
  
  
  // Insert data to database
  $result = $access-&gt;registerUser($username,$securedPassword,$salt,$email,$fullname);
  
  if ($result) {
      // get data from database
  
      $user = $access-&gt;selectUser($username);
  
      $resultArray = [
  
          "status" =&gt; "200",
          "message" =&gt; "Sucessfully registered",
          "id" =&gt; $user["id"],
          "username" =&gt; $user["username"],
          "email" =&gt; $user["email"],
          "avatar" =&gt; $user["avatar"],
          "fullname" =&gt; $user["fullname"]
      ];
  </code></pre>
  
  <p>login process</p>
  
  <pre><code>$username = htmlentities($_REQUEST["username"]);
  $password = htmlentities($_REQUEST["password"]);
  
  if (empty($username) || empty($password)) {
  
      $returnArray = [
          "status" =&gt; "400",
          "message" =&gt; "missing required information"
      ];
  
      echo json_encode($returnArray);
      return;
  
  }
  
  
  // make connection
  $file = parse_ini_file("../../../twitter.ini");
  $dbhost = trim($file["host"]); 
  $dbusername = trim($file["username"]);
  $dbpassword = trim($file["password"]);
  $dbname = trim($file["dbname"]);
  
  
  $access = new access($dbhost,$dbusername,$dbpassword,$dbname);
  $access-&gt;connect();
  
  $user = $access -&gt; getUserData($username);
  
  
  if (empty($user)) {
      $returnArray = [
          "status" =&gt; "403",
          "message" =&gt; "User is not found"
      ];
  
      echo json_encode($returnArray);
      return;
  } else {
  
      // password validation
  
      $securedPassword = $user["password"];
      $salt = $user["salt"]; 
  
  
      if ($securedPassword === sha1($password.$salt)) {
  
          $resultArray = [
  
          "status" =&gt; "200",
          "message" =&gt; "Login Success!",
          "id" =&gt; $user["id"],
          "username" =&gt; $user["username"],
          "email" =&gt; $user["email"],
          "avatar" =&gt; $user["avatar"],
          "fullname" =&gt; $user["fullname"]
      ];
  
      } else {
          $returnArray = [
          "status" =&gt; "403",
          "message" =&gt; "Password didn't match"
      ];
      }
  
  }
  
  
  $access -&gt;disconnect();
  
  
  echo json_encode($returnArray); 
  </code></pre>