【问题标题】:Password security problems密码安全问题
【发布时间】:2017-07-23 12:19:48
【问题描述】:

Web 服务将用户信息存储在数据库中并使用密码进行身份验证。下面是在 ruby​​ 中实现用户密码存储和认证的方式(实际的数据存储和检索超出了示例的范围):

require 'digest'

class User

  # Use salted passwords
  PASSWORD_SALT="trustno1"

  # Stored password hash will be accessible through user.hashed_password
  attr_accessor :hashed_password

  # Authenticates user against given password and returns true
  # the password matches the stored one
  def verify_password(password)
    if hashed_password.nil? || password.nil?
      false
    else
      User.hash_password(password) == hashed_password
    end
  end

  # Changes user's password
  def change_password(new_password)
    self.hashed_password = User.hash_password(new_password.to_s)
  end

  # Hashes the input with salt
  def self.hash_password(password)
    Digest::MD5.hexdigest(password + PASSWORD_SALT)
  end
end

但是,我被告知我遇到了与密码安全相关的问题,但我找不到任何问题。

【问题讨论】:

  • (1) MD5 不适合密码散列(它坏了而且太快了)(2) 你应该为每个密码使用一个新的随机盐 (3) 你不应该尝试在你的密码上实现安全的密码存储拥有但使用现有的(经过验证且安全的)解决方案,例如 Rails 的内置 has_secure_password 选项。

标签: ruby-on-rails ruby authentication passwords


【解决方案1】:

如果你真的想自己在 Rails 中实现这个,你应该使用ActiveModel::SecurePassword::ClassMethods
你最大的问题是你试图自己实现这个。太容易搞砸了。

【讨论】:

    猜你喜欢
    • 2011-01-10
    • 2011-03-09
    • 1970-01-01
    • 2014-02-09
    • 2013-10-30
    • 2011-06-02
    • 2021-07-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多