PageRenderTime 34ms CodeModel.GetById 4ms RepoModel.GetById 0ms app.codeStats 0ms

/BlogEngine/DotNetSlave.BusinessLogic/Security/CustomIdentity.cs

#
C# | 54 lines | 44 code | 8 blank | 2 comment | 3 complexity | dde735b466a9c06824fee0145ed88eae MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0, BSD-3-Clause
  1. namespace BlogEngine.Core
  2. {
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Web.Security;
  8. using System.Security.Principal;
  9. using System.Runtime.Serialization;
  10. using System.Reflection;
  11. using System.Security;
  12. // Need to inherit from MarshalByRefObject to prevent runtime errors with Cassini
  13. // when using a custom identity.
  14. public class CustomIdentity : MarshalByRefObject, IIdentity
  15. {
  16. public string AuthenticationType
  17. {
  18. get { return "BlogEngine.NET Custom Identity"; }
  19. }
  20. private bool _isAuthenticated;
  21. public bool IsAuthenticated
  22. {
  23. get { return _isAuthenticated; }
  24. }
  25. private string _name;
  26. public string Name
  27. {
  28. get { return _name; }
  29. }
  30. public CustomIdentity(string username, bool isAuthenticated)
  31. {
  32. _name = username;
  33. _isAuthenticated = isAuthenticated;
  34. }
  35. public CustomIdentity(string username, string password)
  36. {
  37. if (Utils.StringIsNullOrWhitespace(username))
  38. throw new ArgumentNullException("username");
  39. if (Utils.StringIsNullOrWhitespace(password))
  40. throw new ArgumentNullException("password");
  41. if (!Membership.ValidateUser(username, password)) { return; }
  42. _isAuthenticated = true;
  43. _name = username;
  44. }
  45. }
  46. }