简体   繁体   English

NetworkCredentials以纯文本形式公开密码

[英]NetworkCredentials exposes password in plain text

I'm about to create an authentication module in my C#/WPF application. 我即将在我的C#/ WPF应用程序中创建一个身份验证模块。 To authenticate the user, I would like to use NetworkCredential to store the credentials. 要对用户进行身份验证,我想使用NetworkCredential来存储凭据。

Credential = new NetworkCredential(credential.UserName, credential.Password);

Where the credential.UserName is a string and credential.Password is of the type SecureString . 其中credential.UserNamestringcredential.Password的类型为SecureString When debugging the application I can see the password in plain text as well as in secure string 调试应用程序时,我可以在纯文本和安全字符串中看到密码

在此输入图像描述

Why is the password exposed as plain text? 为什么密码是以纯文本形式公开的? Isn't this a possible security threat? 这不是一个可能的安全威胁吗?

Thanks for answering. 谢谢回答。

EDIT: 编辑:

For the record, the NetworkCredential object shall be used on the WCF client, like this: 对于记录,应在WCF客户端上使用NetworkCredential对象,如下所示:

client.ClientCredentials.Windows.ClientCredential = Credentials

The NetworkCredential class internally always stores the password as a SecureString : NetworkCredential类在内部始终将密码存储SecureString

 public string Password {
        get {
            ExceptionHelper.UnmanagedPermission.Demand();
            return InternalGetPassword();
        }
        set {
            m_password = UnsafeNclNativeMethods.SecureStringHelper.CreateSecureString(value);
        }
    }

When someone needs to retrieve the password as plain text (which at some point will be needed, either from this class or somewhere further down the chain), it retrieves it from the secure string : 当有人需要以纯文本的形式检索密码时(无论是从某个类还是从该类中的某个地方开始),它都会从安全字符串中检索密码

    internal string InternalGetPassword() {
        string decryptedString = UnsafeNclNativeMethods.SecureStringHelper.CreateString(m_password);
        return decryptedString;
    }

When using the debugger, it shows the properties, so the value is retrieved from the SecureString 使用调试器时,它显示属性,因此从SecureString检索值

SecureString has nothing to do with encryption! SecureString与加密无关! (a gross oversimplification - it's possible it's also encrypted, but that's not all that important here; if you create a SecureString from a normal string , you've already negated plenty of gain of SecureString - short-term) (一个粗略的过度简化 - 它可能也加密了,但这里并不重要;如果你从普通string创建一个SecureString ,你已经否定了SecureString大量收益 - 短期)

It's simply a string that can be deterministically deallocated. 它只是一个可以确定性地解除分配的字符串。 This is important for security reasons, since .NET strings may be very long lived (for interned strings, the whole life of the application). 出于安全原因,这很重要,因为.NET字符串可能非常长寿(对于实习字符串,应用程序的整个生命周期)。

NetworkCredential is not used for storing credentials - it's just a simple wagon to get them where they are going - a common API, basically. NetworkCredential不用于存储凭证 - 它只是一个简单的马车,可以让它们到达目的地 - 基本上是一个常见的API。

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

相关问题 在会话.NET中存储纯文本密码 - Storing plain text password in session .NET 储存密码的最佳方法(无数据库或纯文本)? - Best way to store password (no database or plain text)? 在 NetworkCredentials 中提供用户名和密码时,.net 中的 HttpClient 发出 2 个请求 - HttpClient in .net issues 2 requests when providing username and password in NetworkCredentials 在Session ASP .NET MVC中存储密码,如纯文本 - Store password like a plain text in Session ASP .NET MVC 将纯文本密码迁移到asp.net Identity 2.1 - Migrating plain-text password to asp.net Identity 2.1 从 HttpClient 更改为 Webclient,以纯文本形式发送密码 - Changing from HttpClient to Webclient, sending password as plain text 在SQL中最终需要以纯文本格式存储密码的最佳方法是什么? - What would be the best way of storing a password in SQL that needs to eventually be in plain text? 在WCF中使用Windows身份验证类型时,是否以纯文本格式发送用户名和密码? - Are username and password sent in plain text when using windows authentication type in WCF? 是否可以将密码以纯文本形式存储在内存中,而不保存在数据库,文件等中? - Can password be stored in plain text as long as its in memory, and not persisted in database, files etc.? NetWorkCredentials 未显示在标题中 - NetWorkCredentials not showing up in headers
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM