reset restful authentication user password from rails console

Hi,

I have implemented restful authentication plugin in my rails application. It’s a barebones implementation without activation, forget password features …etc. I was wondering if it is possible to reset a User’s password from the rails console? As things stand now, there is no other way to reset their passwords :).

Any help in this regard will be appreciated.

Regards, Andrew

Haven't used restful auth in a long long time, but you should be able to do exactly what a controller would do when setting a password:

user.password = 'imAdummy' user.password_confirmation = 'imAdummy' user.save!

Fred

Hi,

I have implemented restful authentication plugin in my rails application.

It’s a barebones implementation without activation, forget password features …etc. I was wondering if it is possible to reset a User’s password from the rails console? As things stand now, there is no other way to reset their

passwords :).

Haven’t used restful auth in a long long time, but you should be able to do exactly what a controller would do when setting a password:

user.password = ‘imAdummy’

user.password_confirmation = ‘imAdummy’ user.save!

Fred

–Hi Fred,

The users table has crypted_password, and salt columns which is giving me problems when I try to reset password from the console.After reading the documentation for restful authentication, it appears that the I need to store the hashed password in crypted_password field. Therefore, I approached the problem as follows:

Loading development environment (Rails 2.3.5)

require ‘digest/sha1’ => user=User.find_by_login(‘admin’) => #<User id: 2, login: “admin”, name: “”, email: “admin@gmail.com”, crypted_pas

sword: “b6fe78bbb5f6f1b2c7e6061a2e2a80bbdc538194”, salt: “502d171c369fac51309dd9 1aea49c9cabe9eed20”, created_at: “2010-05-17 08:54:44”, updated_at: “2010-05-17 09:21:30”, remember_token: nil, remember_token_expires_at: nil, admin: true>

user.crypted_password=Digest::SHA1.hexdigest(“kramer”) => “060938ead8dbea8fece5711eb89b8e097d79e8d5” user.salt => “502d171c369fac51309dd91aea49c9cabe9eed20”

user.save => true quit

Eventhough everything appears to go smoothly and also user.save returns “true”, I am unable to login as admin. Have I overlooked something?

Thanks in advance for your help

Andrew

the password needs to be hashed with the salt. However you don't to know any of that - normally you'll have a before_save :encrypt_password or something like that: if you set password & password_confirmation then restful auth will do the hashing for you when you save the record

Fred

…just do what he said and it should work fine.

(I say this, b/c I just opened up my app and tried it, and it worked)

andrew v wrote:

Hi,

I have implemented restful authentication plugin in my rails application.

[...]

Great. Now take it out and put in Authlogic or something. restful_authentication relies on unmaintainable generated code, and no Rails developer should even consider using it now that better alternatives exist.

Best,

Hi Fred,

You got it spot on! It finally worked. I was barking up the wrong tree. Thanks a lot for your help mate! Now I’ve got to figure out the rest of the functionality for my application. But at least now I know where to seek help :slight_smile:

Cheers, Andrew

Hi Marnen,

Apparently I was looking in the wrong places or was reading dated RoR stuff 'cause wherever I looked RA was the overwhelming favorite for authentication. But considering the problems I’ve had thus far with RA, I’ll surely look into authlogic for my next project. If I run into any problems, I’m sure I can count on your help :slight_smile:

Thanks and Regards, Andrew

andrew v wrote:

Hi Marnen,

Apparently I was looking in the wrong places or was reading dated RoR stuff 'cause wherever I looked RA was the overwhelming favorite for authentication.

It used to be. It's pretty easy to use, and its API isn't bad (though not as slick as Authlogic). The problem is all the crap it puts in your User model, mixed in with the code you actually wanted to have in there. Authlogic is much more self-contained. (I've heard good things about Devise and some others too, but never tried them.)

But considering the problems I've had thus far with RA, I'll surely look into authlogic for my next project. If I run into any problems, I'm sure I can count on your help :slight_smile:

I'll be what help I can.

Thanks and Regards, Andrew

On Sat, May 29, 2010 at 12:17 AM, Marnen Laibow-Koser

Best,