示例#1
0
        /// <summary>
        /// 检测验证码,返回ClientId
        /// </summary>
        /// <param name="inputCode"></param>
        /// <param name="encryptCode"></param>
        /// <returns></returns>
        public string CheckVerifyCode(string inputCode, string encryptCode)
        {
            string str = WuYao.AesDecrypt(encryptCode);

            if (string.IsNullOrEmpty(str))
            {
                throw new Exception("你还想不想登录了!");
            }
            string[] stra = str.Split('$');
            if (stra == null || stra.Length == 0)
            {
                throw new Exception("系统有误!");
            }
            if (WuYao.GetMd5(inputCode.ToUpper()) != stra[1])
            {
                throw new Exception("验证码有误!");
            }
            SqlHelper _sql = new SqlHelper();
            DataTable dt   = _sql.Query("SELECT * FROM tbl_loginverifycode WITH(nolock) WHERE ClientId = @id",
                                        new System.Collections.Generic.Dictionary <string, object> {
                { "@id", stra[0] }
            });

            if (dt == null || dt.Rows.Count == 0)
            {
                throw new Exception("验证码已失效!");
            }
            if (DateTime.UtcNow.Ticks > long.Parse(Cast.ConToString(dt.Rows[0]["Ticks"])))
            {
                throw new Exception("验证码已失效!");
            }
            return(stra[0]);
        }
示例#2
0
文件: AuthHelper.cs 项目: SkyQAQ/Blog
 /// <summary>
 /// 重置密码
 /// </summary>
 /// <param name="receive"></param>
 /// <param name="verifycode"></param>
 /// <returns></returns>
 public string ResetPwd(string receive, string verifycode)
 {
     try
     {
         string valid = ValidReceiveVerifyCode(receive, Constants.CodeTypeForgetPwd, verifycode);
         if (!string.IsNullOrEmpty(valid))
         {
             return(valid);
         }
         string password = Rand.Str(8);
         _sql.OpenDb();
         _sql.Execute("UPDATE UserInfo SET Password = @password WHERE Email = @receive", new Dictionary <string, object> {
             { "@password", WuYao.GetMd5(password + Constants.PasswordSalt) }, { "@receive", receive }
         });
         if (receive.Contains("@"))
         {
             EmailHelper.SendEmailByQQ(receive, "淮安市三轮车开黑网站-重置密码", string.Format("重置密码:{0};请尽快登录并修改密码!", password), Constants.CodeTypeForgetPwd);
             return("重置密码已发送至注册邮箱!");
         }
         else
         {
             return("");
         }
     }
     catch (Exception ex)
     {
         _log.Error(ex.Message, ex);
         throw ex;
     }
     finally
     {
         _sql.CloseDb();
     }
 }
示例#3
0
        /// <summary>
        /// 加密验证码
        /// </summary>
        /// <param name="text">验证码</param>
        /// <returns></returns>
        private static string EncryptVcCode(string text)
        {
            string    clientId  = Guid.NewGuid().ToString();
            string    code      = WuYao.GetMd5(text.ToUpper());
            string    plainText = clientId + "$" + code + "$" + Rand.Str_char(6);
            SqlHelper _sql      = new SqlHelper();

            _sql.OpenDb();
            _sql.Execute(string.Format("insert into tbl_loginverifycode values('{0}','{1}',{2})", clientId, text, DateTime.UtcNow.AddMinutes(3).Ticks));
            _sql.CloseDb();
            return(WuYao.AesEncrypt(plainText));
        }
示例#4
0
文件: AuthHelper.cs 项目: SkyQAQ/Blog
 /// <summary>
 /// 创建账号
 /// </summary>
 /// <param name="receive"></param>
 /// <param name="verifycode"></param>
 /// <returns></returns>
 public string CreateUser(string receive, string verifycode)
 {
     try
     {
         string valid = ValidReceiveVerifyCode(receive, Constants.CodeTypeRegister, verifycode);
         if (!string.IsNullOrEmpty(valid))
         {
             return(valid);
         }
         string    account  = string.Empty;
         string    password = Rand.Str(8);
         DataTable dtEmail  = _sql.Query("SELECT UserInfoId FROM UserInfo WHERE Email = @email", new Dictionary <string, object> {
             { "@email", receive }
         });
         if (dtEmail != null && dtEmail.Rows.Count > 0)
         {
             return("当前邮箱账号密码已发送,请检查邮箱!");
         }
         DataTable dtAccount = null;
         do
         {
             account   = Rand.Number(8);
             dtAccount = _sql.Query("SELECT UserInfoId FROM UserInfo WHERE Account = @account", new Dictionary <string, object> {
                 { "@account", account }
             });
         } while (dtAccount != null && dtAccount.Rows.Count > 0);
         _sql.OpenDb();
         UserInfo user = new UserInfo();
         user.Account  = account;
         user.Password = WuYao.GetMd5(password + Constants.PasswordSalt);
         user.Email    = receive;
         Guid      userId = _sql.Create(user);
         DataTable dtRole = _sql.Query("SELECT RoleInfoId FROM RoleInfo WHERE RoleCode = @code", new Dictionary <string, object> {
             { "@code", RoleKey.JCQX }
         });
         if (dtRole != null && dtRole.Rows.Count > 0)
         {
             UserInRole ur = new UserInRole();
             ur.UserInfoId = userId;
             ur.UserCode   = account;
             ur.RoleCode   = RoleKey.JCQX;
             ur.RoleInfoId = Guid.Parse(Cast.ConToString(dtRole.Rows[0]["RoleInfoId"]));
             _sql.Create(ur);
         }
         if (receive.Contains("@"))
         {
             EmailHelper.SendEmailByQQ(receive, "淮安市三轮车开黑网站-注册账号", string.Format("账号:{0} \n 密码:{1}", account, password), Constants.CodeTypeRegister);
             return("账号密码已发送至注册邮箱!");
         }
         else
         {
             return("");
         }
     }
     catch (Exception ex)
     {
         _log.Error(ex.Message, ex);
         throw ex;
     }
     finally
     {
         _sql.CloseDb();
     }
 }