コード例 #1
0
ファイル: api.ashx.cs プロジェクト: ZhouWenhua907/Lottery
        /// <summary>
        /// 修改密码
        /// </summary>
        /// <returns></returns>
        private Hashtable ChangePwd(HttpContext context)
        {
            Hashtable htRet = new Hashtable();

            try
            {
                string sOldPwd = CConvert.ToString(context.Request["opwd"]).Trim();
                string sNewPwd = CConvert.ToString(context.Request["npwd"]).Trim();

                FastReadServer.admin.UserInfo user = (FastReadServer.admin.UserInfo)context.Session[FastReadServer.admin.CConst.CSession.C_UserInfoKey];
                if (user == null || user.UserId == "")
                {
                    htRet["msg"] = "用户信息超时,请重新登录!";
                    htRet["ok"]  = false;
                    return(htRet);
                }
                string sUid = user.UserId;

                DBIndex dbm = new DBIndex();

                DataSet ds = new DBLogin().GetUserInfoById(sUid);
                if (ds.Tables[0].Rows.Count == 0)
                {
                    htRet["msg"] = "用户不存在!";
                    htRet["ok"]  = false;
                    return(htRet);
                }
                if (System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(sOldPwd, "MD5") != CConvert.ToString(ds.Tables[0].Rows[0]["pwd"]))
                {
                    htRet["msg"] = "旧密码不正确!";
                    htRet["ok"]  = false;
                    return(htRet);
                }

                int iRet = dbm.ChangePwd(sUid, System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(sNewPwd, "MD5"));
                if (iRet == 0)
                {
                    htRet["msg"] = "服务器异常,请联系管理员!";
                    htRet["ok"]  = false;
                    return(htRet);
                }
                else
                {
                    htRet["ok"] = true;
                }
            }
            catch (Exception ex)
            {
                htRet["ok"]  = false;
                htRet["msg"] = "处理失败!" + ex.Message;
            }
            return(htRet);
        }