【问题标题】:Is this a good security/validation method to use in WCF services?这是在 WCF 服务中使用的良好安全/验证方法吗?
【发布时间】:2014-01-05 17:00:48
【问题描述】:

我正在创建一个主机/客户端样式,它使用 WCF 及其 wsHttpBinding 将客户端与运行主机的服务器进行通信,我想提供某种安全性或验证,所以我有这个,我想知道它有多好或有多安全是。

服务库中的每个方法都有一个 USERNAME 和 PASSWORD 变量,这两个变量都必须填充一个由客户端使用 SHA512 哈希算法进行哈希处理的值。因此,该方法的用户名、密码和任何其他参数都被发送到服务器,服务器将根据哈希用户名和密码的数据库检查哈希用户名和密码,以查看是否找到匹配项。如果匹配,则返回客户端请求的数据,但如果不匹配,则返回错误或消息并且不发回数据。具有此“安全性”的方法的代码片段如下:

// The USERNAME and PASSWORD parameter values have been hashed by the client before
[OperationContract]
string SayHello(string USERNAME, string PASSWORD, string name)

//-------------------------------------------------------------------

public string SayHello(string USERNAME, string PASSWORD, string name)
{
    if (USERNAME == "username" & PASSWORD == "password")
    { return string.Format("Hello, {0}!", name); }
    else { return "Invalid credentials, method aborted"; }
}

这是验证“呼叫”的良好安全方法吗?更多的是检查他们是否有帐户而不是安全,但我认为这可能非常安全。你怎么看,它有多安全或有多好,但更重要的是,它怎么可能被黑客或其他方法破解?

【问题讨论】:

    标签: c# wcf security hash cryptography


    【解决方案1】:

    这篇文章应该对你有所帮助:How to: Authenticate with a User Name and Password

    WSHttpBinding userNameBinding = new WSHttpBinding();
    userNameBinding.Security.Mode = SecurityMode.Message;
    userNameBinding.Security.Message.ClientCredentialType = MessageCredentialType.UserName;
    svcHost.AddServiceEndpoint(typeof(IService1), userNameBinding, "");
    ...
    
    string username;
    string password;
    
    // Instantiate the proxy
    Service1Client proxy = new Service1Client();
    
    // Prompt the user for username & password
    GetPassword(out username, out password);
    
    // Set the user’s credentials on the proxy
    proxy.ClientCredentials.UserName.UserName = username;
    proxy.ClientCredentials.UserName.Password = password;
    
    // Treat the test certificate as trusted
    proxy.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = 
        System.ServiceModel.Security.X509CertificateValidationMode.PeerOrChainTrust;
    // Call the service operation using the proxy
    

    【讨论】:

      猜你喜欢
      • 2012-12-25
      • 2012-04-08
      • 1970-01-01
      • 1970-01-01
      • 2010-12-21
      • 2014-07-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多