在登录页面上显示设计最小密码长度错误

时间:2014-03-12 13:03:25

标签: ruby ruby-on-rails-3 devise

我正在使用设计的可验证模块,而devise.rb已编写 config.password_length = 10..128 ,但在登录时未验证密码长度。需要停止用户如果密码不在指定的密码长度之间,则登录。

请帮忙。

提前致谢。

1 个答案:

答案 0 :(得分:0)

此选项不会影响登录。它会验证保存记录时用户的密码长度应介于8到128个字符之间。

<强>更新

如果您想阻止某人登录,则需要覆盖active_for_authentication?

class User
  def active_for_authentication?
    super && password_is_long_enough?
  end

  def password_is_long_enough?
    # logic to check password is long enough
  end
end

但是,由于密码是经过哈希处理的,因此您不知道它有多长时间,因此我不确定这会对您有所帮助:(