Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/04/09 19:42:18 (15 years ago)
Author:
svonolfe
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Security.Core/3.2/PermissionManager.cs

    r1736 r1737  
    88using HeuristicLab.DataAccess.Interfaces;
    99using HeuristicLab.PluginInfrastructure;
     10using System.Security.Cryptography;
    1011
    1112namespace HeuristicLab.Security.Core {
     
    1920    Object locker = new Object();
    2021
    21  
     22    private static string getMd5Hash(string input) {
     23      // Create a new instance of the MD5CryptoServiceProvider object.
     24      MD5 md5Hasher = MD5.Create();
     25
     26      // Convert the input string to a byte array and compute the hash.
     27      byte[] data = md5Hasher.ComputeHash(Encoding.Default.GetBytes(input));
     28
     29      // Create a new Stringbuilder to collect the bytes
     30      // and create a string.
     31      StringBuilder sBuilder = new StringBuilder();
     32
     33      // Loop through each byte of the hashed data
     34      // and format each one as a hexadecimal string.
     35      for (int i = 0; i < data.Length; i++) {
     36        sBuilder.Append(data[i].ToString("x2"));
     37      }
     38
     39      // Return the hexadecimal string.
     40      return sBuilder.ToString();
     41    }
     42
    2243   /// <summary>
    2344   /// If a session exists for this userName then it is returned, otherwise the given password
     
    3455        session = factory.GetSessionForCurrentThread();
    3556
     57        password = getMd5Hash(password);
     58
    3659        IUserAdapter userAdapter = session.GetDataAdapter<User, IUserAdapter>();
    3760        User user = userAdapter.GetByLogin(userName);
    3861
    39         if (user.Password.CompareTo(password) == 0) {
     62        if (user != null &&
     63            user.Password.Equals(password)) {
    4064          Guid newSessionId = Guid.NewGuid();
    4165          lock (locker)
     
    105129      return Guid.Empty;
    106130    }
    107 
    108     public void TestServer() {
    109     }
    110131  }
    111132}
Note: See TracChangeset for help on using the changeset viewer.