我怎么能防止暴力重试密码

时间:2015-09-18 00:13:47

标签: ruby-on-rails-4

我通过电子邮件向用户发送私人链接

  = link_to user_profile_url(user_token: @user.token, user_id: @user.uid), method: :post

避免让用户再次从移动邮件应用程序登录。如果请求有user_token, user_id参数,我会允许用户登录。

因为我现在的方法可以在短时间内强力尝试。

避免暴力攻击的最佳做法是什么,谢谢

  def get_user_by_token(user_id=nil ,token=nil)
    if user_id and token
        User.where({id: user_id, token: token}).first
    else 
        nil
    end

  end

1 个答案:

答案 0 :(得分:1)

您基本上有两个补充选项:

  1. 使令牌复杂到足以需要相当大的计算工作量。您可以使用SecureRandom.hex甚至SecureRandom.urlsafe_base64,其中不仅包括字母和数字,还包括其他字符。
  2. 限制动作。跟踪对该特定操作的HTTP请求,并在每分钟的请求数高于(例如5)时通过IP阻止用户。