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