Free cookie consent management tool by TermsFeed Policy Generator

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

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

following changes (#1046):

  • extended HeuristicLabUser.cs (additional methods)
  • implemented a 2. demo method for HeuristicLabMembershipProvider.cs
  • recreated two test classes in English language
File size: 3.3 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    public override string GetPassword(string passwordAnswer) {
75      if (PasswordAnswer == passwordAnswer) {
76        return Password;
77      } else {
78        return "";
79      }
80    }
81
82    public override string ResetPassword() {
83      Password = "INIT";
84      return Password;
85    }
86
87    public override string ResetPassword(string passwordAnswer) {
88      if (PasswordAnswer == passwordAnswer) {
89        Password = "INIT";
90        return Password;
91      } else {
92        return "";
93      }
94    }
95
96    public override string ToString() {
97      return UserName;
98    }
99
100    //
101    // Summary:
102    //     Clears the locked-out state of the user so that the membership user can be
103    //     validated.
104    //
105    // Returns:
106    //     true if the membership user was successfully unlocked; otherwise, false.
107    public override bool UnlockUser() {
108      throw new NotImplementedException();
109    }
110  }
111}
Note: See TracBrowser for help on using the repository browser.