Problem with registered in custom API user

System Information
  • Strapi Version: 4.1.7
  • Operating System: macOS Monterey
  • Database: PostgreSql
  • Node Version: v14.19.0
  • NPM Version: 6.14.16
  • Yarn Version: 1.22.15

Hello!
I have a strange problem with creating users.
I created custom API using strapi generate.
In that API I am creating new users with this code:

let newUser = {
  username: phoneNumber,
  email: phoneNumber + "@example.com",
  password: smsCode.toString(),
};

let user = await strapi.entityService.create(“plugin::users-permissions.user”, {
data: newUser,
});

where username is phone number - +79999999999
and password is code from SMS.

The user is created in the database and I can see him in Strapi Admin,
but, when I trying to login with this data, using /api/auth/local, I am getting error - Invalid identifier or password.

But if I create user with the same data in Strapi Admin, all is fine, and I can login with this data.

What can be a reason of this problem?

Hey @anisimov , did you find any solution for the problem mentioned above. I am facing the same issue.

The problem is that the password is being hashed somewhere internally.

I have spent 2 days looking for an answer to this.

Here are some things that I have realized although I have not found an answer either:
-The password is hashed and encrypted but it is not clear which Strapi service is providing this or where to find it.
-There is something besides entityService which supposedly automatically hashes the password.

I have tried bcrypt, authutils,

The most recent thing I tried was
const password = await strapi.service("admin::auth").hashPassword("testtest");

I can’t seem to get it to work although everything else works fine.

Even though it is a bit older. But the trick is to set

“provider”: “local”

to the user data. This way you can use the user to login with the local (username/password) provider.