Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Security.Contracts/3.2/BusinessObjects/User.cs @ 3507

Last change on this file since 3507 was 1738, checked in by asimon, 15 years ago

error correction (ticket #537)

File size: 2.4 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Collections.Generic;
24using System.Text;
25using System.Runtime.Serialization;
26using System.Security.Cryptography;
27
28namespace HeuristicLab.Security.Contracts.BusinessObjects {
29
30  [DataContract]
31  public class User : PermissionOwner {
32
33    [DataMember]
34    public String Login { get; set; }
35
36    private String password;
37   
38    [DataMember]
39    public String Password {
40      get {
41        return this.password;
42      }
43      protected set {
44        this.password = value;
45      }
46    }
47
48    [DataMember]
49    public String MailAddress { get; set; }
50
51    public void SetPlainPassword(String password) {
52      this.password = password;
53    }
54
55    public void SetHashedPassword(String password) {
56      this.password = getMd5Hash(password);
57    }
58
59    private static string getMd5Hash(string input) {
60      // Create a new instance of the MD5CryptoServiceProvider object.
61      MD5 md5Hasher = MD5.Create();
62
63      // Convert the input string to a byte array and compute the hash.
64      byte[] data = md5Hasher.ComputeHash(Encoding.Default.GetBytes(input));
65
66      // Create a new Stringbuilder to collect the bytes
67      // and create a string.
68      StringBuilder sBuilder = new StringBuilder();
69
70      // Loop through each byte of the hashed data
71      // and format each one as a hexadecimal string.
72      for (int i = 0; i < data.Length; i++) {
73        sBuilder.Append(data[i].ToString("x2"));
74      }
75
76      // Return the hexadecimal string.
77      return sBuilder.ToString();
78    }
79  }
80}
Note: See TracBrowser for help on using the repository browser.