Skip to content

Instantly share code, notes, and snippets.

@cogree
cogree / BasicAuthentication.cs
Created January 13, 2016 14:04
Provided the value of an "Authorization" header, you will get a bool result and the username and password if successful.
public static bool TryParseBasicAuthentication(string header, out string username, out string password)
{
username = null; password = null;
try
{
if (!header.StartsWith("Basic "))
return false;
// Remove the scheme and optional space after colon if present.