How to hash a password in PHP to POST via /api/users to create a new user?

chripal2 months ago

Hi,

I am using PHP and curl to create users via API. I need help to understand how to hash a password to post it via /api/users
I am posting json encoded data like this:

        curl_setopt($curl, CURLOPT_HTTPHEADER, array(
            'Content-Type: application/json',
            'Content-Length: ' . strlen(json_encode($data))
        ));

and get password from form:

'password' => $form->get('password'),

User is is created fine but password is not working, need to reset password via e-mail to get it work.

Thanks in advance to any help or informations.

Best regards,
Chris.

Anton Tananaev2 months ago

You don't need to hash the password. It's done on the server side.

chripal2 months ago

Hi Anton,

but if I am sending clear password then user can't login to traccar system using email and password, got 'Invalid username or password' message.
After password reset the account is OK.
I see in database that value in hashedpassword field is hashed, what could be wrong?

Anton Tananaev2 months ago

Have you compared your request with what the official app sends? That will show you what you're doing incorrectly.

chripal2 months ago

hashedpassword and salt are diffrent in db (on 'api created user' and 'official app created user'), everything other fields are the same in tc_users table
I have used same clear passwords to create but I think it isn't the issue.
How to compare it better?

Anton Tananaev2 months ago

You have to compare the API request. You can use some proxy or wireshark to see the requests.

chripal2 months ago

Ok, thx a lot, I have haproxy before Traccar API, but a log is not containing this informations, need to make some changes in system then will try to debug my problem.

chripal2 months ago

I found :-)
If I have copied and paste the password to Traccar system from mail or https page just after my form response it is not working, but if I enter the same pass via keyboard type it working fine.
I don't know why but it is ok for me, I know that my form is working ok.
Thank you for your support!