【问题标题】:Rails bcrypt lost passwordRails bcrypt 丢失密码
【发布时间】:2013-05-30 15:41:51
【问题描述】:

您好,我正在尝试在 rails 中使用 bcrypt 来忘记密码。我采用了 bcrypt 文档中描述的方法“forgot_password”,并为它制作了一个邮件程序。 我已经在我的用户模型中设置了这个方法,比如 self.forgot_password

我试图在 session/new 中的登录表单下的表单中调用此方法,但我认为我没有这样做的好方法。 这是我的表单代码:

<%= 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 %>

【问题讨论】:

    标签: ruby-on-rails passwords bcrypt


    【解决方案1】:

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

    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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-20
      • 2016-01-03
      • 2019-10-11
      • 2020-12-20
      • 2021-08-31
      • 2014-06-19
      相关资源
      最近更新 更多