Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/278.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# AuthenticationHeaderValue中的冒号字符_C#_Authentication - Fatal编程技术网

C# AuthenticationHeaderValue中的冒号字符

C# AuthenticationHeaderValue中的冒号字符,c#,authentication,C#,Authentication,在阅读有关基本身份验证的内容时,我总能找到类似的示例: HttpClient sClient new HttpClient(); sClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic",Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes("UserName:Password"))); 在我看来,这似乎意

在阅读有关基本身份验证的内容时,我总能找到类似的示例:

HttpClient sClient new HttpClient();
sClient.DefaultRequestHeaders.Authorization = 
  new AuthenticationHeaderValue("Basic",Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes("UserName:Password")));
在我看来,这似乎意味着冒号字符“:”不应在密码中使用。这是否意味着密码和用户名应禁止使用冒号字符


这是基本身份验证的一般假设吗?如果您的凭证中存在冒号字符的现有用户库,如何处理此问题。

从技术上讲,
在用户名中是禁止的:

要接收授权,客户端发送用户ID和密码,
由一个冒号(“:”)字符分隔,在base64[7]中
凭据中的编码字符串。
基本凭证=base64用户通行证
base64用户通行证=
用户通行证=用户ID:“密码”
用户ID=*
密码=*文本
值得注意的是:RFC2617没有说明如果用户名包含冒号该怎么办。IE和Firefox都只是简单地将其包括在内,这可能是最糟糕的选择

如果您的用户名包含
,您可能应该将其转义到
%3a
,以将其与分隔符区分开来。服务器是否支持,取决于服务器

话虽如此,HTTP Basic是一个非常糟糕的身份验证方案;使用更好地保护客户端凭据的工具是更好的选择

To receive authorization, the client sends the userid and password,
separated by a single colon (":") character, within a base64 [7]
encoded string in the credentials.

  basic-credentials = base64-user-pass
  base64-user-pass  = <base64 [4] encoding of user-pass,
                   except not limited to 76 char/line>
  user-pass   = userid ":" password
  userid      = *<TEXT excluding ":">
  password    = *TEXT