# 导入用户时设置随机密码

**URL:** <https://meta.discourse.org/t/setting-a-random-password-on-importing-users/120857>\
**Category:** Development\
**Created:** [2019年六月20日 00:54 UTC](https://meta.discourse.org/t/setting-a-random-password-on-importing-users/120857 "2019-06-20T00:54:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![csmu](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/csmu/32/124581_2.png) [@csmu](https://meta.discourse.org/u/csmu)\
**Post date:** [2019年六月20日 00:54 UTC](https://meta.discourse.org/t/setting-a-random-password-on-importing-users/120857/1 "2019-06-20T00:54:35Z")

</div>

We’re importing a club membership list.

We’ve created random passwords for each member which will be SMS’d to them with the expectation they will change their password.

Say I have a password `mozrT9M8Gp` for a user we’re importing … how do I set the password\_hash and salt such that if they decide to login without asking for a password reset it will work?

---

<div class="post-metadata">

**Author:** ![Stephen](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/stephen/32/95011_2.png) [@Stephen](https://meta.discourse.org/u/Stephen)\
**Post date:** [2019年六月20日 00:55 UTC](https://meta.discourse.org/t/setting-a-random-password-on-importing-users/120857/2 "2019-06-20T00:55:39Z")

</div>

Is that easier than the passwordless first visit for new users invited via the usual method?

What’s the problem you’re trying to solve by doing this?

---

<div class="post-metadata">

**Author:** ![csmu](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/csmu/32/124581_2.png) [@csmu](https://meta.discourse.org/u/csmu)\
**Post date:** [2019年六月20日 01:03 UTC](https://meta.discourse.org/t/setting-a-random-password-on-importing-users/120857/3 "2019-06-20T01:03:19Z")

</div>

> [@Stephen](#):
>
> Is that easier than the password first visit for new users invited via the usual method?

Cool. I wasn’t aware of that.

> [@Stephen](#):
>
> What’s the problem you’re trying to solve by doing this?

I want to make it as seamless as possible for club members to be notified of community events. I think I have to make them active, approved with a password set in order to enable them to be able to respond via email.

---

<div class="post-metadata">

**Author:** ![Stephen](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/stephen/32/95011_2.png) [@Stephen](https://meta.discourse.org/u/Stephen)\
**Post date:** [2019年六月20日 01:06 UTC](https://meta.discourse.org/t/setting-a-random-password-on-importing-users/120857/4 "2019-06-20T01:06:41Z")

</div>

As long as you’ve verified the email address somewhere else the risk is probably minimal, but I’ve found a lot of success using the existing invite/enrollment loop. Users typically respond to it very positively.

---

<div class="post-metadata">

**Author:** ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)\
**Post date:** [2019年六月20日 19:51 UTC](https://meta.discourse.org/t/setting-a-random-password-on-importing-users/120857/5 "2019-06-20T19:51:44Z")

</div>

If you are creating the users with an import script, You can just send them a link to the reset password modal.
