1

A little background first, I was able to get the - Angular/Rails project working on local

I went to change the user/password in sqlite3 and here are the steps that I took

rails c
a = User.find(1)
a.name = "myName"
a.password_digest = "mySurName"
a.save

Great, it worked! NOT

Well, kind of, but the Angular app is looking for a password that looks something like this - $2a$10$TrTjNCWr5KlwW2h9aJr45u8MwLDo2ErEFQp1/ixc.8KW...

After doing some digging, I found a stackoverflow answer

Followed by me trying to do the following:

a = User.find(1)
filters = Rails.application.config.filter_parameters
f = ActionDispatch::Http::ParameterFilter.new filters
b = f.filter :password_digest => 'mySurName'
a.password_digest = b

Which results in an error that is in the subject line of this post - TypeError: can't cast Hash to string, followed by (0.1ms) rollback transaction and tons of lines of references to .rb files

So, my ultimate question is, how do I update a record that has a filter on a password field, while using rails console?

Thanks in advance

Community
  • 1
  • 1
kronus
  • 902
  • 2
  • 16
  • 34

2 Answers2

0

You should read up on password hashing and storage, your password should never be stored as plaintext. Just a hunch, try this instead:

a = User.find(1)
a.name = "whatever"
a.password = "something"
a.save

In devise (and probably others) a password setter is defined for the User model which automatically stores the hash of the password in the password_digest column.

Slicedpan
  • 4,995
  • 2
  • 18
  • 33
0

OK, while reading another post to something that was somewhat unrelated - here's the answer:

a = User.new(:name => "Luke", :password => "Skywalker", :password_confirmation => "Skywalker")
a.save

Which creates something like this:

password_digest: "$2a$10$OPlc1rCZscqPkFYSp10NQeTmDRNs1iuv6D0VLAKk8sXu..."
kronus
  • 902
  • 2
  • 16
  • 34