# Setting a password for a user with ruby

**URL:** https://meta.discourse.org/t/setting-a-password-for-a-user-with-ruby/141455
**Category:** Development
**Created:** [February 13, 2020, 1:05am UTC](https://meta.discourse.org/t/setting-a-password-for-a-user-with-ruby/141455 "2020-02-13T01:05:51Z")
**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: [February 13, 2020, 1:05am UTC](https://meta.discourse.org/t/setting-a-password-for-a-user-with-ruby/141455/1 "2020-02-13T01:05:51Z")

</div>

How do you change a user password in the Ruby console?

---

<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: [February 13, 2020, 11:23am UTC](https://meta.discourse.org/t/setting-a-password-for-a-user-with-ruby/141455/2 "2020-02-13T11:23:40Z")

</div>

An easy way to set a user password is

```
  rake admin:create

```

You have the option of making them an admin. You can look at the source for that take task to see how to do it in ruby.

---

<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: [February 13, 2020, 11:08pm UTC](https://meta.discourse.org/t/setting-a-password-for-a-user-with-ruby/141455/3 "2020-02-13T23:08:21Z")

</div>

> [@pfaffman](#):
>
> rake admin:create

```ruby
user.password = password

```

The code looks like password is plain text.  
Does the assignment set the hash?

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [February 14, 2020, 12:59am UTC](https://meta.discourse.org/t/setting-a-password-for-a-user-with-ruby/141455/4 "2020-02-14T00:59:50Z")

</div>

> [@csmu](#):
>
> The code looks like password is plain text.  
> Does the assignment set the hash?

Yes when we save passwords we only save the hash and salt.

---

<div class="post-metadata">

### Author: ![j.jaffeux](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/j.jaffeux/32/60297_2.png) [@j.jaffeux](https://meta.discourse.org/u/j.jaffeux)
#### Post date: [February 16, 2020, 12:59am UTC](https://meta.discourse.org/t/setting-a-password-for-a-user-with-ruby/141455/5 "2020-02-16T00:59:52Z")

</div>

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.
