3

Hi I'm trying to make a forgot password using bcrypt in rails. I've taken the method "forgot_password" described in the bcrypt documentation and made a mailer for it. I've set this method in my user model like self.forgot_password

I'm trying to call this method in a form just under the login form in sessions/new but I think I don't have the good way to do it. Here is my form code :

<%= form_for :user, :url=>{:action=>"forgot_password"} do |f| %>
  <p>Réintialiser mon mot de passe en renseignant votre email ci-dessous :</p>
    <div class="field">
        <%= f.text_field :email, :placeholder=>"ex: cdupont@gmail.com" %>
          </div>
            <div class="actions">
          <%= f.submit "Me renvoyer un email", :class => 'btn btn-warning'   %></center>
            </div> 
            <% end %>
4

1 回答 1

2

给他们随机分配一个并邮寄给他们,要求他们更改

def forgot_password
@user = User.find_by_email(params[:email])
  random_password = Array.new(10).map { (65 + rand(58)).chr }.join
  @user.password = random_password
  @user.save!
  Mailer.create_and_deliver_password_change(@user, random_password)
end

看看这个:https ://github.com/codahale/bcrypt-ruby

于 2014-11-13T09:03:20.713 回答