简体   繁体   English

创建登录系统的最佳方法是什么?

[英]What is the best approach of creating a login System?

I am always wondering that the login systems I have created is vulnerable to attacks or not. 我一直想知道我创建的登录系统是否容易受到攻击。

As many other programmers I also use sessions to hold a specific token token to know the login status. 与许多其他程序员一样,我也使用会话来保存特定的令牌令牌,以了解登录状态。 Cookies to hold the username or even sometime saved status. Cookies,用于保存用户名或什至是保存状态。

What I am wondering is, Is this the right way? 我想知道的是,这是正确的方法吗? Is there any approach better than this? 有没有比这更好的方法了?

You could create your own custom checks on the session. 您可以在会话上创建自己的自定义检查。 Make sure it's created by the same user agent and from the same IP address. 确保它是由相同的用户代理和相同的IP地址创建的。

Other than that, sessions are pretty solid. 除此之外,会议非常扎实。

In the login section, you would do something like: 在登录部分,您将执行以下操作:

$_SESSION['_user_agent'] = $_SERVER['HTTP_USER_AGENT'];
$_SESSION['_remote_addr'] = $_SERVER['REMOTE_ADDR'];

and then you can do a check in every request: 然后您可以在每个请求中进行检查:

function sessionIsOK ()
{
    return ($_SESSION['_user_agent'] == $_SERVER['HTTP_USER_AGENT'] &&
        $_SESSION['_remote_addr'] == $_SERVER['REMOTE_ADDR']);
}

我认为是否使用https很重要:如果使用http而不是https,则系统存在许多漏洞:例如重播和中间人/中继。

An alternative to the common PHP login systems is HTTP authentication. 常见的PHP登录系统的替代方法是HTTP身份验证。 This doesn't require the use of sessions/cookies. 这不需要使用会话/ cookie。 Especially the HTTP Digest authentication is more secure than unencrypted <form> logins. 特别是HTTP Digest身份验证比未加密的<form>登录更为安全。 (Most shared hosting providers don't provide SSL. And if, most FLOSS webapps rarely set it up.) (大多数共享托管服务提供商不提供SSL。如果这样,大多数FLOSS Web应用程序都很少设置它。)

However, there are some usability drawbacks, which can only be alleviated by heavy DHTML/AJAX use. 但是,存在一些可用性缺陷,只有通过大量使用DHTML / AJAX才能缓解这些缺陷。 And it drains server performance a little. 而且会稍微降低服务器性能。 And most important: it's too difficult to implement right for most programmers. 最重要的是:对于大多数程序员而言,实施正确的做法太困难了。

If a simple PHP login system is sufficient, depends on the type of your application. 如果简单的PHP登录系统就足够了,则取决于您的应用程序的类型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM