public User Register([FromBody] User user) { _conn = new Connection(_connectionString); _conn.OpenConnection(); //Calculate MD5 hash MD5 md5 = MD5.Create(); byte[] inputBytes = Encoding.ASCII.GetBytes(user.Username + user.PasswordHash + DateTime.Now); byte[] hash = md5.ComputeHash(inputBytes); StringBuilder tokenString = new StringBuilder(); for (int i = 0; i < hash.Length; i++) { tokenString.Append(hash[i].ToString("X2")); } bool result = _conn.Register(user.Username, user.PasswordHash, tokenString.ToString()); _conn.CloseConnection(); if (result) { user.Token = tokenString.ToString(); return user; } else { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Conflict)); } }