安全登录脚本应该包含哪些内容? [英] What should a secure login script consist of?

查看:46
本文介绍了安全登录脚本应该包含哪些内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要写一个安全登录脚本,我想问一下它应该有什么样的组件.

I am going to write a secure login script and I would like to ask what kind of component it should have.

暂时想到的就是这些

基础

  • 使用 PDO 作为 mysql 数据库的连接器
  • 使用 SHA512 保护密码(是否应该涉及盐/令牌?)
  • 会话和 cookie 管理,试图避免会话 ID 劫持(你能给我提供一些关于它的文章吗?)
  • XSS 预防(你能给我推荐一篇文章吗?)
  • 输入的 SQL 注入预防卫生
  • 通过 https 的安全连接

注册

  • 关于使用 reCaptcha 进行注册

登录

  • 计算登录尝试次数并在 5 次失败尝试后阻止以防止暴力攻击.

登录后

  • 具有破坏功能的会话计时器(12 分钟取消会话),单击以更新计时器 [有人有这样的例子吗?我找不到任何]

还有什么我应该考虑的主要安全提示吗?

Are there any more major security hints that I should think off?

谢谢.

推荐答案

这实际上是一个非常重要的问题,需要考虑许多问题.幸运的是,很多问题已经为您解决了.

This is actually a nontrivial problem with a number of issues that need to be considered. Fortunately, a lot of the problems have been solved for you.

  • 密码哈希: 使用 password_hash()password_verify() -- 不要使用像 MD5 或 SHA1 这样的快速哈希,也不要使用快速哈希不要推出自己的散列策略,否则您会发现自己草率地重新发明了 PBKDF2 -- password_hash() 可以完成您可能想要它做的所有事情,而不必强调实现细节.它们是足够的;好好学习这些工具.如果您使用的是 PHP <5.5 使用password_compat
  • 数据库 API: PDO 很棒.确保充分利用准备好的语句将 SQL 查询与用户提供的数据分开.否则,厄运.
  • 会话管理:使用内置会话,在没有混合内容的任何地方使用HTTPS,设置"httponly""secure"true.当权限提升(例如用户登录)时重新生成会话.

  • Password hashing: Use password_hash() and password_verify() -- don't use fast hashes like MD5 or SHA1, and also don't roll your own hashing strategy or else you'll find yourself reinventing PBKDF2 sloppily -- password_hash() does everything you probably want it to do without having to stress over implementation details. They are adequate; learn these tools well. If you're on PHP < 5.5 use password_compat
  • Database API: PDO is wonderful. Make sure you take full advantage of prepared statements to separate SQL queries from user-supplied data. Otherwise, doom.
  • Session Management: Use the built-in sessions, use HTTPS everywhere with no mixed content, set "httponly" and "secure" to true. Regenerate the session when privilege is escalated (e.g. the user logs in).

如果您想成为偏执狂,您可以防御会话固定攻击(通过设置 canary 会话变量,这些日子实际上并不实用).页面加载时,如果 $_SESSION['canary'] 未定义(或与预期值不匹配),则销毁会话并将用户视为新访客.

If you want to be paranoid, you can defend against session fixation attacks (which aren't really considered practical these days) by setting a canary session variable. Upon page load, if $_SESSION['canary'] is not defined (or does not match an expected value), destroy the session and treat the user as a new guest.

我希望通过 Paragon Initiative Enterprises 博客上的一系列非常详尽的博文来回答这个主题

This is a subject I am hoping to answer through a series of very thorough blog posts on the Paragon Initiative Enterprises blog.

这篇关于安全登录脚本应该包含哪些内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆