Пример #1
0
        /// <summary>
        /// 验证验证码是否正确
        /// </summary>
        /// <param name="mobile">手机号</param>
        /// <param name="code">验证码</param>
        /// <param name="type">验证码类型</param>
        /// <param name="remove">是否验证成功后删除记录</param>
        /// <returns>JsonResult</returns>
        public JsonResult VerifyCode(string mobile, string code, int type, bool remove = true)
        {
            var verify = General.Verify(mobile + Secret);

            if (!verify.Successful)
            {
                return(verify);
            }

            SmsCodes.RemoveAll(c => c.FailureTime < DateTime.Now);
            var record = SmsCodes.FirstOrDefault(c => c.Mobile == mobile && c.Code == code && c.Type == type);

            if (record == null)
            {
                return(verify.SMSCodeError());
            }

            if (!remove)
            {
                return(verify);
            }

            SmsCodes.RemoveAll(c => c.Mobile == mobile && c.Type == type);
            return(verify);
        }
Пример #2
0
        /// <summary>
        /// 用户重置登录密码
        /// </summary>
        /// <param name="account">登录账号</param>
        /// <param name="password">新密码</param>
        /// <param name="code">短信验证码</param>
        /// <returns>JsonResult</returns>
        public JsonResult ResetSignature(string account, string password, string code)
        {
            var verify  = new SessionVerify();
            var session = verify.Basis;

            if (session == null)
            {
                return(verify.Result.NotFound());
            }

            var sign = Hash(session.LoginName.ToUpper() + code + password);

            if (verify.Session.Signature != sign)
            {
                return(verify.Result.InvalidAuth());
            }

            // 验证短信验证码
            var mobile = session.LoginName;

            SmsCodes.RemoveAll(c => c.FailureTime < DateTime.Now);
            var record = SmsCodes.FirstOrDefault(c => c.Mobile == mobile && c.Code == code && c.Type == 2);

            if (record == null)
            {
                return(verify.Result.SMSCodeError());
            }

            SmsCodes.RemoveAll(c => c.Mobile == mobile && c.Type == 2);

            // 更新用户登录密码
            var reset = Update(account, password);

            if (reset == null || !reset.Value)
            {
                return(verify.Result.DataBaseError());
            }

            session.Signature = Hash(account.ToUpper() + password);
            return(verify.Result.Success(CreateKey(session)));
        }