2002-08-26 Gonzalo Paniagua Javier <gonzalo@ximian.com>
[mono.git] / mcs / class / System.Web / System.Web.Security / FormsAuthenticationTicket.cs
1 //
2 // System.Web.Security.FormsAuthenticationTicket
3 //
4 // Authors:
5 //      Gonzalo Paniagua Javier (gonzalo@ximian.com)
6 //
7 // (C) 2002 Ximian, Inc (http://www.ximian.com)
8 //
9
10 using System;
11
12 namespace System.Web.Security
13 {
14         [Serializable]
15         public sealed class FormsAuthenticationTicket
16         {
17                 int version;
18                 string name;
19                 DateTime issueDate;
20                 DateTime expiration;
21                 bool isPersistent;
22                 string userData;
23                 string cookiePath;
24
25                 public FormsAuthenticationTicket (int version,
26                                                   string name,
27                                                   DateTime issueDate,
28                                                   DateTime expiration,
29                                                   bool isPersistent,
30                                                   string userData)
31                 {
32                         this.version = version;
33                         this.name = name;
34                         this.issueDate = issueDate;
35                         this.expiration = expiration;
36                         this.isPersistent = isPersistent;
37                         this.userData = userData;
38                         //FIXME: cookiePath???
39                 }
40
41                 public FormsAuthenticationTicket (int version,
42                                                   string name,
43                                                   DateTime issueDate,
44                                                   DateTime expiration,
45                                                   bool isPersistent,
46                                                   string userData,
47                                                   string cookiePath)
48                 {
49                         this.version = version;
50                         this.name = name;
51                         this.issueDate = issueDate;
52                         this.expiration = expiration;
53                         this.isPersistent = isPersistent;
54                         this.userData = userData;
55                         this.cookiePath = cookiePath;
56                 }
57
58                 public FormsAuthenticationTicket (string name, bool isPersistent, int timeout)
59                 {
60                         this.version = 1;
61                         this.name = name;
62                         this.issueDate = DateTime.Now;
63                         this.isPersistent = isPersistent;
64                         if (isPersistent)
65                                 expiration = issueDate.AddYears (50);
66                         else
67                                 expiration = issueDate.AddMinutes ((double) timeout);
68
69                         this.userData = String.Empty;
70                         //FIXME: cookiePath???
71                 }
72
73                 public string CookiePath
74                 {
75                         get {
76                                 return cookiePath;
77                         }
78                 }
79
80                 public DateTime Expiration
81                 {
82                         get {
83                                 return expiration;
84                         }
85                 }
86
87                 public bool Expired
88                 {
89                         get {
90                                 return DateTime.Now > expiration;
91                         }
92                 }
93
94                 public bool IsPersistent
95                 {
96                         get {
97                                 return isPersistent;
98                         }
99                 }
100
101                 public DateTime IssueDate
102                 {
103                         get {
104                                 return issueDate;
105                         }
106                 }
107
108                 public string Name
109                 {
110                         get {
111                                 return name;
112                         }
113                 }
114
115                 public string UserData
116                 {
117                         get {
118                                 return userData;
119                         }
120                 }
121
122                 public int Version
123                 {
124                         get {
125                                 return version;
126                         }
127                 }
128         }
129 }
130