2011-04-19 42 views
0

我正在寫一個WCF服務,並希望使用CustomUserNameValidator。我在MSDN網站上找到了以下代碼。我想通常會從數據庫檢查用戶名和密碼,這是有道理的。但爲什麼下面的硬編碼代碼被認爲是不安全的?WCF自定義用戶名驗證器:爲什麼這個代碼被認爲是不安全的?

// 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這篇文章討論將用戶名/密碼放在配置文件中。但不明白這與對兩個密碼進行硬編碼有什麼不同。
有人請賜教嗎?

回答

2

撇開有限數量的憑證,您將以明文形式存儲密碼,因此如果有人拿到您的組件,密碼就可以供所有人查看。配置文件選項至少可以告訴ASP.NET對配置文件的那部分進行加密,因此,如果泄漏,它就毫無價值。

相關問題