【问题标题】:what is necessary for authentication to be secure身份验证需要什么才能确保安全
【发布时间】:2017-03-09 20:29:29
【问题描述】:

我目前正在尝试了解 Sinatra,但我注意到没有像设计用于 rails 的最新身份验证 gem。我决定创建自己的身份验证系统,我的问题是,我需要采取哪些最重要的预防措施来确保我的用户安全?我需要以哈希形式存储密码,可能使用盐,但还有什么? 请记住,我不是安全专家,否则不会问这个问题。

【问题讨论】:

标签: ruby authentication sinatra


【解决方案1】:

尝试使用 bcrypt gem

加密密码

谨慎对待会话劫持

例如

post "/signup" do
  password_salt = BCrypt::Engine.generate_salt
  password_hash = BCrypt::Engine.hash_secret(params[:password], password_salt)

  #ideally this would be saved into a database, hash used just for sample
  userTable[params[:username]] = {
    :salt => password_salt,
    :passwordhash => password_hash 
  }

  session[:username] = params[:username]
  redirect "/"
end

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2018-03-05
  • 2020-10-20
  • 2016-01-23
  • 1970-01-01
  • 2015-11-03
  • 2021-12-27
  • 2010-11-24
相关资源
最近更新 更多