コード例 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="password"></param>
        /// <param name="userPassport"></param>
        /// <returns></returns>
        bool IPassportSecurityStrategy.Verify(string password, UserPassport userPassport)
        {
            password.AssertNotNull("password");
            userPassport.AssertNotNull("userPassport");
            userPassport.UserSecurity.AssertNotNull("userPassport.UserSecurity");

            var formatTimes = GetFormatTimes(password, userPassport.UserSecurity.HashAlgorithm);

            password = FormatPassword(formatTimes, password, userPassport);
            return(BCrypt.Verify(password, userPassport.UserSecurity.Password));
        }
コード例 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="password"></param>
        /// <param name="userPassport"></param>
        /// <returns></returns>
        bool IPassportSecurityStrategy.Verify(string password, UserPassport userPassport)
        {
            password.AssertNotNull("password");
            userPassport.AssertNotNull("userPassport");
            userPassport.UserSecurity.AssertNotNull("userPassport.UserSecurity");

            password = FormatPassword(password, userPassport);
            var formatTimes  = GetFormatTimes(password, userPassport.UserSecurity.HashAlgorithm);
            var passwordHash = ComputeHash(password, formatTimes);

            return(passwordHash == userPassport.UserSecurity.Password);
        }
コード例 #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="password"></param>
        /// <param name="userPassport"></param>
        /// <returns></returns>
        string IPassportSecurityStrategy.HashPassword(string password, UserPassport userPassport)
        {
            password.AssertNotNull("password");
            userPassport.AssertNotNull("userPassport");
            userPassport.UserSecurity.AssertNotNull("userPassport.UserSecurity");

            var formatTimes = int.MaxValue;

            if (string.IsNullOrEmpty(userPassport.UserSecurity.HashAlgorithm))
            {
                formatTimes = GetFormatTimes(password, null);
                userPassport.UserSecurity.HashAlgorithm = string.Concat(AlgorithmName, MD5InitialFactor + formatTimes);
                userPassport.UserSecurity.PasswordSalt  = GenerateSalt(formatTimes);
            }
            else
            {
                formatTimes = GetFormatTimes(password, userPassport.UserSecurity.HashAlgorithm);
            }

            password = FormatPassword(password, userPassport);
            return(ComputeHash(password, formatTimes));
        }