簡體   English   中英

Rails Bcrypt丟失密碼

[英]Rails bcrypt lost password

嗨,我正在嘗試使用bcrypt在rails中創建一個忘記密碼。 我已經采用了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 %>

隨機分配給他們,然后郵寄給他們,要求他們進行更改

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM