How to create a new user in pure sql

Thank you for the app.yml tip, that did work.

1 Like

Okay Im testing this out:

  1. Installed migrationpassword plugin
  2. Enabled ‘Allow migratepassword allow insecure passwords’ option
  3. Created new user (via api)
  4. Added password hash into custom fields
    e.g insert into user_custom_fields (user_id, name, value, created_at, updated_at) values (2,‘import_pass’,‘2aee1c40222c7754d4534xxxxxxx’, now(), now());
  5. Try and login as new user with password form old forum

It fails with ‘Incorrect username, email or password’, but I am confused about your answer above, the api wont let me create a user unless I provide a password ( I just used the md5 hash), but you say if there is a password it will prevail over the md5 hash ?

1 Like

I wouldn’t advise using the md5 hash as a password, it will be used as the actual password. If you won’t be needing the password field upon user creation, just use a long random string instead.

What I was trying to say is that Discourse will first try to log in the user by matching the password entered by the user with the stored password. Only when that attempt fails, the migratepassword plugin will come into play, and it will try to see if the user supplied password is correct by matching it against the custom field using a number of built-in alternative hashing algorithms (md5 being one of them).

3 Likes

Ah, sorry my bad, i had put the wrong value for password hash into user_custom_fields.okay that fixes it thankyou…

… however

Even though I created the user with activate true, and it says the user is activated when I look at the user from the admin console when try to login it says:

You can’t log in yet. We previously sent an activation email to you at user@email.com . Please follow the instructions in that email to activate your account.

Why do I get that, I was trying to avoid that.

1 Like

Works for me… any errors you’re getting?

When I try to go to the site I get Error 502, and I left it for a few hours the last time.
But dont notice any errors from where I run the command.

Sorry, but I am going to close this off as “please don’t do that”

Too risky, and there are many side effects you are likely to forget.

2 Likes