Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Services.Authentication Prototype/Persistence/HeuristicLabUser.cs @ 3943

Last change on this file since 3943 was 3943, checked in by hmayr, 14 years ago

following changes (#1046):

  • extended DatabaseUtil.cs
  • extended HeuristicLabUser.cs
  • created HeuristicLabUserTest.cs
  • created AbstractHeuristicLabTest.cs
  • implemented a demo method in HeuristicLabMembershipProvider.cs to show usage of HeuristicLabUser.cs and DatabaseUtil.cs
File size: 3.9 KB
Line 
1using System;
2using System.Web.Security;
3
4namespace Persistence {
5  /// <summary>
6  /// implements the MembershipUser for HeuristicLab
7  /// </summary>
8  partial class HeuristicLabUser : MembershipUser {
9    public HeuristicLabUser(string name, string email, string passwordQuestion, string comment) : this() {
10      _UserName = name;
11      Password = "INIT"; // just for tests
12      _LastPasswordChangedDate = System.DateTime.Today;
13      _PasswordQuestion = passwordQuestion;
14      PasswordAnswer = "";
15      Email = email;
16      Comment = comment;
17    }
18
19    public override bool ChangePassword(string oldPassword, string newPassword) {
20      if (oldPassword == null) {
21        throw new ArgumentNullException("oldPassword");
22      }
23      if (newPassword == null) {
24        throw new ArgumentNullException("newPassword");
25      }
26      if (oldPassword.Length == 0) {
27        throw new ArgumentException("Parameter oldPassword must not be empty!");
28      }
29      if (newPassword.Length == 0) {
30        throw new ArgumentException("Parameter newPassword must not be empty!");
31      }
32
33      if (Password.CompareTo(oldPassword) == 0) {
34        Password = newPassword;
35        return true;
36      } else {
37        return false;
38      }
39    }
40
41    public override bool ChangePasswordQuestionAndAnswer(string password, string newPasswordQuestion, string newPasswordAnswer) {
42      if (password == null) {
43        throw new ArgumentNullException("password");
44      }
45      if (newPasswordQuestion == null) {
46        throw new ArgumentNullException("newPasswordQuestion");
47      }
48      if (newPasswordAnswer == null) {
49        throw new ArgumentNullException("newPasswordAnswer");
50      }
51      if (password.Length == 0) {
52        throw new ArgumentException("Parameter password must not be empty!");
53      }
54      if (newPasswordQuestion.Length == 0) {
55        throw new ArgumentException("Parameter newPasswordQuestion must not be empty!");
56      }
57      if (newPasswordAnswer.Length == 0) {
58        throw new ArgumentException("Parameter newPasswordAnswer must not be empty!");
59      }
60
61      if (Password.CompareTo(password) == 0) {
62        _PasswordQuestion = newPasswordQuestion;
63        PasswordAnswer = newPasswordAnswer;
64        return true;
65      } else {
66        return false;
67      }
68    }
69
70    public override string GetPassword() {
71      return Password;
72    }
73
74    //
75    // Summary:
76    //     Gets the password for the membership user from the membership data store.
77    //
78    // Parameters:
79    //   passwordAnswer:
80    //     The password answer for the membership user.
81    //
82    // Returns:
83    //     The password for the membership user.
84    public override string GetPassword(string passwordAnswer) {
85      throw new NotImplementedException();
86    }
87
88    //
89    // Summary:
90    //     Resets a user's password to a new, automatically generated password.
91    //
92    // Returns:
93    //     The new password for the membership user.
94    public override string ResetPassword() {
95      throw new NotImplementedException();
96    }
97
98    //
99    // Summary:
100    //     Resets a user's password to a new, automatically generated password.
101    //
102    // Parameters:
103    //   passwordAnswer:
104    //     The password answer for the membership user.
105    //
106    // Returns:
107    //     The new password for the membership user.
108    public override string ResetPassword(string passwordAnswer) {
109      throw new NotImplementedException();
110    }
111
112    public override string ToString() {
113      return UserName;
114    }
115
116    //
117    // Summary:
118    //     Clears the locked-out state of the user so that the membership user can be
119    //     validated.
120    //
121    // Returns:
122    //     true if the membership user was successfully unlocked; otherwise, false.
123    public override bool UnlockUser() {
124      throw new NotImplementedException();
125    }
126  }
127}
Note: See TracBrowser for help on using the repository browser.