PageRenderTime 19ms CodeModel.GetById 15ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

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

#
C# | 54 lines | 44 code | 8 blank | 2 comment | 3 complexity | dde735b466a9c06824fee0145ed88eae MD5 | raw file
 1namespace 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
13    // Need to inherit from MarshalByRefObject to prevent runtime errors with Cassini
14    // when using a custom identity.
15    public class CustomIdentity : MarshalByRefObject, IIdentity
16    {
17        public string AuthenticationType
18        {
19            get { return "BlogEngine.NET Custom Identity"; }
20        }
21
22        private bool _isAuthenticated;
23        public bool IsAuthenticated
24        {
25            get { return _isAuthenticated; }
26        }
27
28        private string _name;
29        public string Name
30        {
31            get { return _name; }
32        }
33
34        public CustomIdentity(string username, bool isAuthenticated)
35        {
36            _name = username;
37            _isAuthenticated = isAuthenticated;
38        }
39
40        public CustomIdentity(string username, string password)
41        {
42            if (Utils.StringIsNullOrWhitespace(username))
43                throw new ArgumentNullException("username");
44
45            if (Utils.StringIsNullOrWhitespace(password))
46                throw new ArgumentNullException("password");
47
48            if (!Membership.ValidateUser(username, password)) { return; }
49
50            _isAuthenticated = true;
51            _name = username;
52        }
53    }
54}