Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Text;
- public static class BasicAuthenticationUtil
- {
- /// <summary>
- /// Parse content of Authorization header.
- /// </summary>
- /// <returns>
- /// true if parsed successfully, false if not.
- /// </returns>
- public static bool ParseAuthorizationHeader(string auth,
- out string username, out string password)
- {
- username = password = string.Empty;
- if (auth == null || auth.Substring(0, 5).ToLower() != "basic")
- { return false; }
- string base64Cred = auth.Substring(6);
- byte[] certBytes = Convert.FromBase64String(base64Cred);
- string[] cert = new UTF8Encoding().GetString(certBytes).Split(':');
- username = cert[0];
- password = cert[1];
- // Vista sends DOMAIN\username
- int d = username.IndexOf('\\');
- if (d != -1)
- { username = username.Remove(0, d + 1); }
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement