Change Password

Hallo to all

I have a big Problem by changing the Password of user. I have a database
with user and theier password and now i want to reset the Password!

admin_controller.rb
def restore_user
@user = User.find_by_id(params[:id])
@user.deleted = false
@user.save
flash[:notice] =“Benutzer #{@user.username} wiederhergestellt”
redirect_to(:action => “list_delete”)
end

user.rb
def password=(pwd)
@password = pwd
create_new_salt
self.hashed_password = User.encrypted_password(self.password,
self.salt)
end

Please can somebody help me??

Thank you

Harald

Harald

I have a big Problem by changing the Password of user.

You didn’t say what your proble is!
Anyway, here is - working - code I use to reset the user’s lost
password.

in the users_controller.rb

def generate_and_send_new_password

@user = User.find_by_login(params[:login])
@user.password_confirmation = @user.password = generate_password

flash[:notice] = “new password sent to #{@user.email}”
PasswordMailer.deliver_new_password( @user, @user.password,
login_url+"?login=#{@user.login}")
render :action => ‘password_changed’
end

src:

http://www.rubyonrailsblog.com/articles/2006/09/29/ruby-on-rails-random-password-generator
def generate_password(length = 6)
chars = (‘a’…‘z’).to_a + (‘A’…‘Z’).to_a + (‘1’…‘9’).to_a -
[‘o’, ‘O’, ‘i’, ‘I’]
Array.new(length) { chars[rand(chars.size)] }.join
end
end

HTH

Alain R.

http://blog.ravet.com

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs