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

Last change on this file since 1737 was 1737, checked in by svonolfe, 12 years ago

Passwords are now stored in MD5 in the database (#532)

File size: 2.3 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    private static string getMd5Hash(string input) {
33      // Create a new instance of the MD5CryptoServiceProvider object.
34      MD5 md5Hasher = MD5.Create();
35
36      // Convert the input string to a byte array and compute the hash.
37      byte[] data = md5Hasher.ComputeHash(Encoding.Default.GetBytes(input));
38
39      // Create a new Stringbuilder to collect the bytes
40      // and create a string.
41      StringBuilder sBuilder = new StringBuilder();
42
43      // Loop through each byte of the hashed data
44      // and format each one as a hexadecimal string.
45      for (int i = 0; i < data.Length; i++) {
46        sBuilder.Append(data[i].ToString("x2"));
47      }
48
49      // Return the hexadecimal string.
50      return sBuilder.ToString();
51    }
52
53
54    [DataMember]
55    public String Login { get; set; }
56
57    private String password;
58   
59    [DataMember]
60    public String Password {
61      get {
62        return this.password;
63      }
64      set {
65        this.password = getMd5Hash(value);
66      }
67    }
68
69    public void SetPlainPassword(String password) {
70      this.password = password;
71    }
72
73    [DataMember]
74    public String MailAddress { get; set; }
75  }
76}
Note: See TracBrowser for help on using the repository browser.