WCF自定义用户名验证器:为什么这段代码被认为是不安全的?

时间:2011-04-19 16:43:31

标签: wcf security wcf-security

我正在编写WCF服务,并希望使用CustomUserNameValidator。我在MSDN网站上找到了以下代码。我猜通常会检查数据库中的用户名和密码,这是有道理的。但为什么以下硬编码的代码被认为是如此不安全?

// This method validates users. It allows in two users, test1 and test2 
// with passwords 1tset and 2tset respectively.
// This code is for illustration purposes only and 
// must not be used in a production environment because it is not secure.    
public override void Validate(string userName, string password)
{
if (null == userName || null == password)
    throw new ArgumentNullException();

if (!(userName == "test1" && password == "1tset") && !(userName == "test2" && password == "2tset"))
    throw new FaultException("Unknown Username or Incorrect Password");
}

我可能有1个或2个用户名(在许多客户端共享,请求来自哪个客户端并不重要)。我找到了this帖子,其中讨论了如何将用户名/密码放入配置文件中。但是不明白这与两个密码的硬编码有什么不同。
有人可以赐教我吗?

1 个答案:

答案 0 :(得分:2)

将有限数量的凭据放在一边,您将密码以明文形式存储,因此如果有人拿到您的程序集,则密码可供所有人查看。配置文件选项至少可以告诉ASP.NET加密配置文件的那一部分,所以,如果它泄漏,它就没用了。