コード例 #1
0
        /// <summary>
        /// ValidateAsync
        /// </summary>
        /// <param name="mobile"></param>
        /// <param name="code"></param>
        /// <returns></returns>
        /// <exception cref="SmsException"></exception>
        public async Task <bool> ValidateAsync(string mobile, string code)
        {
            if (string.IsNullOrWhiteSpace(code) || code.Length != _options.TemplateIdentityValidation.CodeLength || !ValidationMethods.IsAllNumber(code))
            {
                return(false);
            }

            try
            {
                string?cachedSmsCode = await GetSmsCodeFromCacheAsync(mobile).ConfigureAwait(false);

                return(string.Equals(code, cachedSmsCode, GlobalSettings.Comparison));
            }
            catch (CacheException ex)
            {
                throw Exceptions.SmsCacheError("", ex);
            }
        }