Advertisement
Guest User

Untitled

a guest
Feb 6th, 2017
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. using System;
  2. using System.Text;
  3.  
  4. public static class BasicAuthenticationUtil
  5. {
  6. /// <summary>
  7. /// Parse content of Authorization header.
  8. /// </summary>
  9. /// <returns>
  10. /// true if parsed successfully, false if not.
  11. /// </returns>
  12. public static bool ParseAuthorizationHeader(string auth,
  13. out string username, out string password)
  14. {
  15. username = password = string.Empty;
  16.  
  17. if (auth == null || auth.Substring(0, 5).ToLower() != "basic")
  18. { return false; }
  19.  
  20. string base64Cred = auth.Substring(6);
  21.  
  22. byte[] certBytes = Convert.FromBase64String(base64Cred);
  23. string[] cert = new UTF8Encoding().GetString(certBytes).Split(':');
  24. username = cert[0];
  25. password = cert[1];
  26.  
  27. // Vista sends DOMAIN\username
  28. int d = username.IndexOf('\\');
  29. if (d != -1)
  30. { username = username.Remove(0, d + 1); }
  31.  
  32. return true;
  33. }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement