Beispiel #1
0
        internal static bool CompareHash(string hashInstance, byte[] plaintext, byte[] hashedText, ConfigurationContext context)
        {
            ArgumentValidation.CheckForNullReference(hashInstance, "hashInstance");
            ArgumentValidation.CheckForEmptyString(hashInstance, "hashInstance");

            HashProviderFactory factory      = new HashProviderFactory(context);
            IHashProvider       hashProvider = factory.CreateHashProvider(hashInstance);

            return(hashProvider.CompareHash(plaintext, hashedText));
        }
Beispiel #2
0
        public UserForm(DbAuthenticationProviderData dbAuthenticationProvider, ConfigurationContext context)
        {
            this.dbAuthenticationProvider = dbAuthenticationProvider;
            InitializeComponent();

            this.userRoleMgr = new UserRoleManager(dbAuthenticationProvider.Database, context);

            HashProviderFactory hashProviderFactory = new HashProviderFactory(context);
            this.hashProvider = hashProviderFactory.CreateHashProvider(dbAuthenticationProvider.HashProvider);
            UpdateSaveButtonEnabled();
        }
		/// <overrides>
		/// Computes the hash value of plain text using the given hash provider instance
		/// </overrides>
		/// <summary>
		/// Computes the hash value of plain text using the given hash provider instance
		/// </summary>
		/// <param name="hashInstance">A hash instance from configuration.</param>
		/// <param name="plaintext">The input for which to compute the hash.</param>
		/// <returns>The computed hash code.</returns>
		public static byte[] CreateHash(string hashInstance, byte[] plaintext)
		{
			if (string.IsNullOrEmpty(hashInstance)) throw new ArgumentException(Resources.ExceptionNullOrEmptyString, "hashInstance");

			try
			{
				HashProviderFactory factory = new HashProviderFactory(ConfigurationSourceFactory.Create());
				IHashProvider hashProvider = factory.Create(hashInstance);

				return hashProvider.CreateHash(plaintext);
			}
			catch (ConfigurationErrorsException configurationException)
			{
				TryLogHashConfigurationError(configurationException, hashInstance);

				throw;
			}
		}
Beispiel #4
0
        /// <overrides>
        /// Compares plain text input with a computed hash using the given hash provider instance.
        /// </overrides>
        /// <summary>
        /// Compares plain text input with a computed hash using the given hash provider instance.
        /// </summary>
        /// <remarks>
        /// Use this method to compare hash values. Since hashes may contain a random "salt" value, two seperately generated
        /// hashes of the same plain text may result in different values.
        /// </remarks>
        /// <param name="hashInstance">A hash instance from configuration.</param>
        /// <param name="plaintext">The input for which you want to compare the hash to.</param>
        /// <param name="hashedText">The hash value for which you want to compare the input to.</param>
        /// <returns><c>true</c> if plainText hashed is equal to the hashedText. Otherwise, <c>false</c>.</returns>
        public static bool CompareHash(string hashInstance, byte[] plaintext, byte[] hashedText)
        {
            if (string.IsNullOrEmpty(hashInstance))
            {
                throw new ArgumentException(Resources.ExceptionNullOrEmptyString, "hashInstance");
            }

            try
            {
                HashProviderFactory factory      = new HashProviderFactory(ConfigurationSourceFactory.Create());
                IHashProvider       hashProvider = factory.Create(hashInstance);

                return(hashProvider.CompareHash(plaintext, hashedText));
            }
            catch (ConfigurationErrorsException configurationException)
            {
                TryLogHashConfigurationError(configurationException, hashInstance);

                throw;
            }
        }
Beispiel #5
0
        internal static byte[] CreateHash(string hashInstance, byte[] plaintext, ConfigurationContext context)
        {
            ArgumentValidation.CheckForNullReference(hashInstance, "hashInstance");
            ArgumentValidation.CheckForEmptyString(hashInstance, "hashInstance");

            HashProviderFactory factory = new HashProviderFactory(context);
            IHashProvider hashProvider = factory.CreateHashProvider(hashInstance);
            return hashProvider.CreateHash(plaintext);
        }
        /// <devdoc>
        /// Compares the password passed in against the password stored in the database.
        /// </devdoc>
        private bool PasswordsMatch(byte[] password, string userName)
        {
            DbAuthenticationProviderData dbAuthenticationProviderData = (DbAuthenticationProviderData)securityConfigurationView.GetAuthenticationProviderData(ConfigurationName);
            bool result = false;
            UserRoleManager manager = new UserRoleManager(dbAuthenticationProviderData.Database, securityConfigurationView.ConfigurationContext);
            byte[] hashedPassword = manager.GetPassword(userName);

            if (hashedPassword != null)
            {
                HashProviderFactory hashFactory = new HashProviderFactory(securityConfigurationView.ConfigurationContext);
                IHashProvider hashProvider = hashFactory.CreateHashProvider(dbAuthenticationProviderData.HashProvider);
                result = hashProvider.CompareHash(password, hashedPassword);
            }
            return result;
        }