Advertisement
Guest User

Untitled

a guest
Mar 28th, 2019
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. public async Task InvokeAsync(HttpContext context)
  2. {
  3. var authInfo = context.Request.Headers.GetCommaSeparatedValues("Authorization");
  4. string userName = null;
  5. string password = null;
  6.  
  7. if (authInfo.Length > 0)
  8. {
  9. var loginInfo = authInfo[0].Split(" ");
  10.  
  11. if (loginInfo.Length == 2)
  12. {
  13. var base64String = loginInfo[1];
  14. var decodedByteData = System.Convert.FromBase64String(base64String);
  15. var decodedInfo = System.Text.Encoding.UTF8.GetString(decodedByteData).Split(":");
  16. userName = decodedInfo[0];
  17. password = decodedInfo[1];
  18. }
  19. }
  20.  
  21. if (userName == "qwe" && password == "123")
  22. {
  23. await _next.Invoke(context);
  24. }
  25. else
  26. {
  27. context.Response.StatusCode = 403;
  28. await context.Response.WriteAsync($"Not authorized");
  29. }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement