Ejemplo n.º 1
0
 /// <summary>
 /// Rehash a single User's current Password with our intermediate Hash.
 /// </summary>
 /// <param name="userPassword"></param>
 /// <returns></returns>
 private static async Task <UserPasswordDto> HashUserPassword(UserPasswordDto userPassword)
 {
     return(await Task.Run(() =>
     {
         var timer = Stopwatch.StartNew();
         // Current User Password is UpperCase SHA256 hash. Make sure that ToUpper() is called.
         userPassword.Password = HashHelpers.CreateHashWithVersion(userPassword.CurrentPassword.ToUpper(), version: HashVersionEnum.Intermediate_SHA256_Bcrypt);
         timer.Stop();
         Console.WriteLine($"Created Hash for Id {userPassword.Id}, Hash: {userPassword.Password}. Thread {Thread.CurrentThread.ManagedThreadId}. Time: {timer.ElapsedMilliseconds}ms");
         return userPassword;
     }));
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Updates a single user in the database.
        /// </summary>
        /// <param name="user"></param>
        /// <param name="connection"></param>
        private static void UpdateUser(UserPasswordDto user, IDbConnection connection)
        {
            string updateQueryString = "UPDATE Users SET Password = @password WHERE Id = @id AND Password = @currentPassword";

            using (SqlCommand updateCommand = new SqlCommand(updateQueryString, (SqlConnection)connection))
            {
                updateCommand.Parameters.AddWithValue("@id", user.Id);
                updateCommand.Parameters.AddWithValue("@password", user.Password);
                updateCommand.Parameters.AddWithValue("@currentPassword", user.CurrentPassword);
                try
                {
                    updateCommand.ExecuteNonQuery();
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"Exception while updating User {user.Id}, Ex: {ex}");
                }
            }
        }