2 // System.Web.Security.MembershipUser
5 // Ben Maurer (bmaurer@users.sourceforge.net)
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 namespace System
.Web
.Security
35 public class MembershipUser
39 object providerUserKey
;
41 string passwordQuestion
;
45 DateTime creationDate
;
46 DateTime lastLoginDate
;
47 DateTime lastActivityDate
;
48 DateTime lastPasswordChangedDate
;
49 DateTime lastLockoutDate
;
51 protected MembershipUser ()
55 public MembershipUser (string providerName
, string name
, object providerUserKey
, string email
,
56 string passwordQuestion
, string comment
, bool isApproved
, bool isLockedOut
,
57 DateTime creationDate
, DateTime lastLoginDate
, DateTime lastActivityDate
,
58 DateTime lastPasswordChangedDate
, DateTime lastLockoutDate
)
60 this.providerName
= providerName
;
62 this.providerUserKey
= providerUserKey
;
64 this.passwordQuestion
= passwordQuestion
;
65 this.comment
= comment
;
66 this.isApproved
= isApproved
;
67 this.isLockedOut
= isLockedOut
;
68 this.creationDate
= creationDate
.ToUniversalTime ();
69 this.lastLoginDate
= lastLoginDate
.ToUniversalTime ();
70 this.lastActivityDate
= lastActivityDate
.ToUniversalTime ();
71 this.lastPasswordChangedDate
= lastPasswordChangedDate
.ToUniversalTime ();
72 this.lastLockoutDate
= lastLockoutDate
.ToUniversalTime ();
75 void UpdateSelf (MembershipUser fromUser
)
77 try { Comment = fromUser.Comment; }
catch (NotSupportedException
) {}
78 try { creationDate = fromUser.CreationDate; }
catch (NotSupportedException
) {}
79 try { Email = fromUser.Email; }
catch (NotSupportedException
) {}
80 try { IsApproved = fromUser.IsApproved; }
catch (NotSupportedException
) {}
81 try { isLockedOut = fromUser.IsLockedOut; }
catch (NotSupportedException
) {}
82 try { LastActivityDate = fromUser.LastActivityDate; }
catch (NotSupportedException
) {}
83 try { lastLockoutDate = fromUser.LastLockoutDate; }
catch (NotSupportedException
) {}
84 try { LastLoginDate = fromUser.LastLoginDate; }
catch (NotSupportedException
) {}
85 try { lastPasswordChangedDate = fromUser.LastPasswordChangedDate; }
catch (NotSupportedException
) {}
86 try { passwordQuestion = fromUser.PasswordQuestion; }
catch (NotSupportedException
) {}
87 try { providerUserKey = fromUser.ProviderUserKey; }
catch (NotSupportedException
) {}
90 internal void UpdateUser ()
92 MembershipUser newUser
= Provider
.GetUser (name
, false);
96 public virtual bool ChangePassword (string oldPassword
, string newPassword
)
98 bool success
= Provider
.ChangePassword (UserName
, oldPassword
, newPassword
);
105 public virtual bool ChangePasswordQuestionAndAnswer (string password
, string newPasswordQuestion
, string newPasswordAnswer
)
107 bool success
= Provider
.ChangePasswordQuestionAndAnswer (UserName
, password
, newPasswordQuestion
, newPasswordAnswer
);
114 public virtual string GetPassword ()
116 return GetPassword (null);
119 public virtual string GetPassword (string answer
)
121 return Provider
.GetPassword (UserName
, answer
);
124 public virtual string ResetPassword ()
126 return ResetPassword (null);
129 public virtual string ResetPassword (string answer
)
131 string newPass
= Provider
.ResetPassword (UserName
, answer
);
138 public virtual string Comment
{
139 get { return comment; }
140 set { comment = value; }
143 public virtual DateTime CreationDate
{
144 get { return creationDate.ToLocalTime (); }
147 public virtual string Email
{
148 get { return email; }
149 set { email = value; }
152 public virtual bool IsApproved
{
153 get { return isApproved; }
154 set { isApproved = value; }
157 public virtual bool IsLockedOut
{
158 get { return isLockedOut; }
161 public bool IsOnline
{
163 return LastActivityDate
> DateTime
.Now
- TimeSpan
.FromMinutes (Membership
.UserIsOnlineTimeWindow
);
167 public virtual DateTime LastActivityDate
{
168 get { return lastActivityDate.ToLocalTime (); }
169 set { lastActivityDate = value.ToUniversalTime (); }
172 public virtual DateTime LastLoginDate
{
173 get { return lastLoginDate.ToLocalTime (); }
174 set { lastLoginDate = value.ToUniversalTime (); }
177 public virtual DateTime LastPasswordChangedDate
{
178 get { return lastPasswordChangedDate.ToLocalTime (); }
181 public virtual DateTime LastLockoutDate
{
182 get { return lastLockoutDate.ToLocalTime (); }
185 public virtual string PasswordQuestion
{
186 get { return passwordQuestion; }
189 public virtual string ProviderName
{
190 get { return providerName; }
193 public virtual string UserName
{
197 public virtual object ProviderUserKey
{
198 get { return providerUserKey; }
201 public override string ToString ()
206 public virtual bool UnlockUser ()
208 bool retval
= Provider
.UnlockUser (UserName
);
215 MembershipProvider Provider
{
217 MembershipProvider p
= Membership
.Providers
[ProviderName
];
218 if (p
== null) throw new InvalidOperationException ("Membership provider '" + ProviderName
+ "' not found.");