Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Although this function works it may not be the best way and has some bug.
- bool TryGetBasicAutheticationCredentials(string authorizationHeader, out string username, out string password)
- {
- const string schemePrefix = "Basic ";
- if (authorizationHeader != null &&
- authorizationHeader.StartsWith(schemePrefix, System.StringComparison.OrdinalIgnoreCase))
- {
- try
- {
- string authorizationValue = authorizationHeader.Substring(schemePrefix.Length);
- byte[] credentialsBytes = System.Convert.FromBase64String(authorizationValue);
- string credentials = System.Text.Encoding.UTF8.GetString(credentialsBytes);
- string[] tokens = credentials.Split(':');
- username = tokens[0];
- password = tokens[1];
- return true;
- }
- catch
- {
- }
- }
- username = default;
- password = default;
- return false;
- }
Add Comment
Please, Sign In to add comment