Ok i need to add a lost password feature. i need to generate a random password, then hash it and then save the hashed password and in turn mail then their new password.
here is the code i was trying to use, but having issues with it working properly:
Lost Password
def lost_password
if request.post?
if user = User.find_by_email(params[:email])
Create new password
chars = (“a”…“z”).to_a + (“1”…“9”).to_a
@newpass = Array.new(8, ‘’).collect{chars[rand(chars.size)]}.join
@password = Digest::SHA1.hexdigest(@newpass)
User.save = User.password
flash[:notice] = “A new password has been emailed to you.”
Mailer.send(Mailer.new_password, @newpass)
redirect_to login_url
else
flash[:notice] = “Please enter a valid email address”
end
else
flash[:notice] = “”
end
end