M
M
moved_on2015-01-28 00:00:27
PHP
moved_on, 2015-01-28 00:00:27

Attention connoisseurs - md5 lines - different values ​​- why?

Hello. The problem is the following.
Language - php.
I send a POST request to the server. The request parameters are as follows - appdata - {"id":1,"hash":"a08f4db74b7ca13f52b098a3bdc65dd9"} , params - {"asd":123} (generated json).
in the script I process it like this:

if (isset($_POST['appdata'])) //appdata - id,hash of app
      {
        unset($appdata);
        $appdata = json_decode($_POST['appdata'], true);
        if (empty($appdata))
        {
          throw new Exception('$appdata in POST is bad - '.$_POST['appdata'].' from ip - '.$_SERVER["REMOTE_ADDR"], -15);
        }

        unset($soul);
        $soul = _CheckAPP($appdata['id'],$appdata['hash'],$_POST['params']);

where _CheckAPP ​​-
function _CheckAPP($id,$hash,$params)
{
  if (empty($id) || empty($hash) || empty($params))
  {
    throw new Exception('$appdata in POST is bad - '.$_POST['appdata'].' from ip - '.$_SERVER["REMOTE_ADDR"], -15);
  }
  $APP_list=array(
          1 => array(
          'id' => '1',
          'secret' => '882fa0dd30eeca544871f31bc41d244b',
          'soul' => 'asd12wez128&712u4h8-0)611297cg*&'
          )
        );

  if (!isset($APP_list[$id]))
  {
    throw new Exception('This APP Not Registered - '.$id, -11);
  }
  else
  {
    $reg_secret=$APP_list[$id]['secret'];
    $conc_string=$id.$params.$reg_secret;
    if (md5($conc_string)!==$hash)
    {
      throw new Exception('APP Registered - '.$id.' hash is wrong - '.md5($conc_string), -12);
    }
    else
    {
      return $APP_list[$id]['soul'];
    }
  }
}

throws an error - the hash does not match. I get a hash from $conc_string in another script or on a generator site - it does not match what is indicated in the error text.
What could be the problem?
Thank you.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
M
Maxim Kudryavtsev, 2015-01-28
@kumaxim

The problem is most likely in the encodings. To begin with, check the encodings of the files that process your code, utf-8 win-1251 is not critical, the main thing is that there is one thing.
Next, check if you have set the page encoding in the meta tag. Again, one must be the same as the encoding of your files.
If this is true, but still there is an error - convert the string forcibly through iconv

M
moved_on, 2015-01-28
@moved_on

function _CheckAPP($id,$hash,$params)
{
  if (empty($id) || empty($hash) || empty($params))
  {
    throw new Exception('$appdata in POST is bad - '.$_POST['appdata'].' from ip - '.$_SERVER["REMOTE_ADDR"], -15);
  }
  $APP_list=array(
          //APP_OFFICIAL_ANDROID
          1 => array(
          'id' => '1',
          'secret' => '882fa0dd30eeca544871f31bc41d244b',
          'soul' => 'asd12wez128&712u4h8-0)611297cg*&'
          )
        );

  if (!isset($APP_list[$id]))
  {
    throw new Exception('This APP Not Registered - '.$id, -11);
  }
  else
  {
    $reg_secret=$APP_list[$id]['secret'];
    $conc_string=$id.$params.$reg_secret;
    if (md5($conc_string)!==$hash)
    {
      echo md5('1{"asd":23}882fa0dd30eeca544871f31bc41d244b').' ';//тут все ок
      throw new Exception('APP Registered - '.$id.' hash is wrong - '.md5($conc_string).' '.$conc_string.' ', -12);
    }
    else
    {
      return $APP_list[$id]['soul'];
    }
  }
}

try
{
  _CheckAPP(1,"400c09327ea9bf1fe9d2223c5e32c7a6",'{"asd":23}');
}
catch (Exception $e)
{	
  echo $e->getMessage();
}

So, I'm trying to do it differently.
I put everything in a separate script. Does not help..(

A
Alexander Oparin, 2017-08-17
@jack_azizov

The problem is here:
The event must be hung on a separate button, and not on all at once
https://codepen.io/anon/pen/prppmg?editors=1011

I
Igor Koch, 2017-08-17
@amux

https://codepen.io/whata/pen/yoppWO?editors=1010

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question