Пример #1
0
        public async Task <IActionResult> Login(AdminModel model)
        {
            string account  = model.Account.ToLower(),
                   password = Md5Helper.Encrypt(model.Password.ToLower());
            var entity      = _context.Admin.FirstOrDefault(x => x.Account == account && x.Password == password);

            if (entity == null)
            {
                ModelState.AddModelError("login.error", "账号密码不正确");
                return(View(model));
            }

            // 写入cookie
            ClaimsIdentity claimsIdentity = new ClaimsIdentity(new Claim[]
            {
                new Claim(ClaimTypes.Sid, entity.Id.ToString()),
                new Claim(ClaimTypes.NameIdentifier, entity.Account),
                new Claim(ClaimTypes.Name, entity.NickName)
            }, AdminAuthenticationScheme.AdminScheme);

            ClaimsPrincipal claimsPrincipal = new ClaimsPrincipal(claimsIdentity);
            await HttpContext.SignInAsync(AdminAuthenticationScheme.AdminScheme, claimsPrincipal);

            return(RedirectToAction("Index", "Home"));
        }
Пример #2
0
        /// <summary>
        /// 获取桌面配置信息
        /// <summary>
        /// <returns></returns>
        public Response GetMap(dynamic _)
        {
            string ver = this.GetReqData();// 获取模板请求数据

            var target = dTTargetIBLL.GetList();
            var list   = dTListIBLL.GetList();
            var chart  = dTChartIBLL.GetList();

            var data = new
            {
                target,
                list,
                chart
            };
            string md5 = Md5Helper.Encrypt(data.ToJson(), 32);

            if (md5 == ver)
            {
                return(Success("no update"));
            }
            else
            {
                var jsondata = new
                {
                    data = data,
                    ver  = md5
                };
                return(Success(jsondata));
            }
        }
Пример #3
0
        /// <summary>
        /// 修改用户登录密码
        /// </summary>
        /// <param name="newPassword">新密码(MD5 小写)</param>
        /// <param name="oldPassword">旧密码(MD5 小写)</param>
        public bool RevisePassword(string newPassword, string oldPassword)
        {
            try
            {
                UserInfo userInfo = LoginUserInfo.Get();
                cache.Remove(cacheKeyId + userInfo.userId, CacheId.user);
                cache.Remove(cacheKeyAccount + userInfo.account, CacheId.user);

                string oldPasswordByEncrypt = Md5Helper.Encrypt(DESEncrypt.Encrypt(oldPassword, userInfo.secretkey).ToLower(), 32).ToLower();
                if (oldPasswordByEncrypt == userInfo.password)
                {
                    userService.RevisePassword(userInfo.userId, newPassword);
                }
                else
                {
                    return(false);
                }
                return(true);
            }
            catch (Exception ex)
            {
                if (ex is ExceptionEx)
                {
                    throw;
                }
                else
                {
                    throw ExceptionEx.ThrowBusinessException(ex);
                }
            }
        }
Пример #4
0
        public async Task <IActionResult> Login(LoginViewModel login)
        {
            if (ModelState.IsValid)
            {
                var user = await _context.Users.FirstOrDefaultAsync(u => u.UserName == login.UserName);

                if (user == null)
                {
                    ViewData["Message"] = "用户不存在!";
                }
                else
                {
                    if (user.Password == Md5Helper.Encrypt(login.Password, 32))
                    {
                        UserInfo.RealName = user.RealName;
                        UserInfo.Id       = user.Id;
                        SetCurrentId(user.Id);
                        SetCurrentRealName(user.RealName);
                        SetCurrentUserName(user.UserName);
                        return(RedirectToAction(nameof(Index), "Home"));
                    }
                    ViewData["Message"] = "密码错误!";
                }
            }
            return(View());
        }
Пример #5
0
        public ActionResult GetMap(string ver)
        {
            var target = dTTargetIBLL.GetList();
            var list   = dTListIBLL.GetList();
            var chart  = dTChartIBLL.GetList();

            var data = new
            {
                target,
                list,
                chart
            };
            string md5 = Md5Helper.Encrypt(data.ToJson(), 32);

            if (md5 == ver)
            {
                return(Success("no update"));
            }
            else
            {
                var jsondata = new
                {
                    data = data,
                    ver  = md5
                };
                return(Success(jsondata));
            }
        }
Пример #6
0
 /// <summary>
 /// 验证登录
 /// </summary>
 /// <param name="account">账号</param>
 /// <param name="password">密码 MD5 32位 小写</param>
 /// <returns></returns>
 public UserEntity CheckLogin(string account, string password)
 {
     ////调用微信开放平台接口获得Token、OpenId
     //string appid = Config.GetValue("AppId");
     //string appsecret = Config.GetValue("AppSecret");
     //OpenTokenGet openTokenGet = new OpenTokenGet();
     //openTokenGet.appid = appid;
     //openTokenGet.secret = appsecret;
     //openTokenGet.code = "0815LTNN0EEei42rURNN0z5QNN05LTNS";
     //OpenTokenGetResult openInfo = openTokenGet.OpenSend();
     //string openid = openInfo.openid;
     //string token = openInfo.access_token;
     ////调用微信开放平台接口获得登录用户个人信息
     //OpenUserGet openuser = new OpenUserGet();
     //openuser.openid = openid;
     //openuser.access_token = token;
     //OpenUserGetResult userinfo = openuser.OpenSend();
     try
     {
         UserEntity userEntity = GetEntityByAccount(account);
         if (userEntity == null)
         {
             userEntity = new UserEntity()
             {
                 LoginMsg = "账户不存在!",
                 LoginOk  = false
             };
             return(userEntity);
         }
         userEntity.LoginOk = false;
         if (userEntity.F_EnabledMark == 1)
         {
             string dbPassword = Md5Helper.Encrypt(DESEncrypt.Encrypt(password.ToLower(), userEntity.F_Secretkey).ToLower(), 32).ToLower();
             if (dbPassword == userEntity.F_Password)
             {
                 userEntity.LoginOk = true;
             }
             else
             {
                 userEntity.LoginMsg = "密码和账户名不匹配!";
             }
         }
         else
         {
             userEntity.LoginMsg = "账户被系统锁定,请联系管理员!";
         }
         return(userEntity);
     }
     catch (Exception ex)
     {
         if (ex is ExceptionEx)
         {
             throw;
         }
         else
         {
             throw ExceptionEx.ThrowBusinessException(ex);
         }
     }
 }
Пример #7
0
        /// <summary>
        /// 重置密码
        /// </summary>
        /// <param name="Phone">手机号</param>
        /// <param name="Pwd">密码</param>
        /// <param name="VerifiCode">验证码</param>
        /// <returns></returns>

        public ActionResult ResetPwd(string Phone, string Pwd, string VerifiCode)
        {
            try
            {
                if (Phone.IsEmpty() || Phone.Length != 11)
                {
                    return(Fail("手机号不能为空或格式错误!"));
                }
                if (Pwd.IsEmpty())
                {
                    return(Fail("密码不能为空!"));
                }
                if (VerifiCode.IsEmpty())
                {
                    return(Fail("验证码不能为空!"));
                }
                string        appid         = CheckAPPID();
                dm_userEntity dm_UserEntity = dm_userIBLL.GetEntityByPhone(Phone, appid);

                if (dm_UserEntity == null)
                {
                    return(Fail("该手机号未注册!"));
                }
                dm_UserEntity.pwd = Md5Helper.Encrypt(Pwd, 16);
                dm_userIBLL.SaveEntity(dm_UserEntity.id.ToInt(), dm_UserEntity);
                return(Success("密码修改成功,请重新登录!"));
            }
            catch (Exception ex)
            {
                return(FailException(ex));
            }
        }
Пример #8
0
 /// <summary>
 /// 保存用户表单(新增、修改)
 /// </summary>
 /// <param name="keyValue">主键值</param>
 /// <param name="userEntity">用户实体</param>
 /// <returns></returns>
 public void SaveEntity(string keyValue, UserEntity userEntity)
 {
     try
     {
         if (string.IsNullOrEmpty(keyValue))
         {
             userEntity.Create();
             userEntity.F_Secretkey = Md5Helper.Encrypt(CommonHelper.CreateNo(), 16).ToLower();
             userEntity.F_Password  = Md5Helper.Encrypt(DESEncrypt.Encrypt(userEntity.F_Password, userEntity.F_Secretkey).ToLower(), 32).ToLower();
             this.BaseRepository().Insert(userEntity);
         }
         else
         {
             userEntity.Modify(keyValue);
             userEntity.F_Secretkey = null;
             userEntity.F_Password  = null;
             this.BaseRepository().Update(userEntity);
         }
     }
     catch (Exception ex)
     {
         if (ex is ExceptionEx)
         {
             throw;
         }
         else
         {
             throw ExceptionEx.ThrowServiceException(ex);
         }
     }
 }
Пример #9
0
        public void Encrypt32_Test(string originStr, string result)
        {
            var helper = new Md5Helper();
            var actual = helper.Encrypt(originStr);

            Assert.Equal(result, actual);
        }
Пример #10
0
        public async Task <ApiResult> Insert(UserInsertReq req)
        {
            if (req == null)
            {
                return(Error("请求参数不能为空"));
            }

            SysUser role = new SysUser
            {
                UserName = req.UserName,
                Password = Md5Helper.Encrypt(req.Password),
                RealName = req.RealName,
                NickName = req.NickName,
                Avator   = req.Avator,
                Mobile   = req.Mobile,
                Email    = req.Email,
                Remark   = req.Remark,
                CreateBy = CurrentUser.UserId
            };
            var res = await _userService.InsertAsync(role);

            if (res > 0)
            {
                return(Success("添加成功"));
            }
            return(Success("添加失败"));
        }
Пример #11
0
        public async Task <ApiResult> Login(LoginReq login)
        {
            if (string.IsNullOrEmpty(login.UserName))
            {
                return(Error("用户名不能为空"));
            }
            if (string.IsNullOrEmpty(login.Password))
            {
                return(Error("密码不能为空"));
            }
            var password = Md5Helper.Encrypt(login.Password);
            var user     = await _userService.FindFirstOrDefaultAsync(m => m.UserName == login.UserName && m.Password == password);

            if (user == null)
            {
                return(Error("用户名或密码错误"));
            }
            UserInfo loginUserRes = new UserInfo
            {
                UserId   = user.Id,
                UserName = user.UserName,
                NickName = user.NickName,
                Avator   = user.Avator,
                Mobile   = user.Mobile,
                Email    = user.Email,
                //Depts = new List<long>(),
                //Roles = new List<long>(),
                //GrantedModules = new List<TreeNode>()
            };
            var depts = await GetUserDepts(user.Id);

            var roles = await GetUserRoles(user.Id, depts);

            var moduleList = await GetUserModules(roles);

            var treeNode = new GrantedModule();

            TreeHelper.ListToTree(treeNode, moduleList);
            //loginUserRes.GrantedModules = treeNode.Children;

            #region 设置用户基本信息
            RedisHelper.Set($"User${user.Id}", loginUserRes, 60 * 60 * 24);
            #endregion

            Dictionary <string, string> dic = new Dictionary <string, string>
            {
                { "UserId", user.Id.ToString() },
                { "UserName", user.UserName }
            };
            var token = TokenHelper.GenerateToken(dic, 60);
            var res   = new
            {
                token,
                userInfo = loginUserRes,
                moduleList
            };
            return(Success(res));
        }
Пример #12
0
        public async Task <Media> SaveMediaAsync(Stream mediaBinaryStream, string fileName, string mimeType = null)
        {
            var bytes = new byte[mediaBinaryStream.Length];

            using (mediaBinaryStream)
            {
                mediaBinaryStream.Read(bytes, 0, bytes.Length);
            }
            var hsMd5 = Md5Helper.Encrypt(bytes);
            var media = await _mediaRepository.Query(c => c.Md5 == hsMd5).FirstOrDefaultAsync();

            if (media != null)
            {
                return(media);
            }

            var result = await Task.Run(() =>
            {
                return(Upload(bytes, hsMd5, fileName));
            });

            if (result == null || result.Content == null || string.IsNullOrWhiteSpace(result.Content.DownloadUrl))
            {
                return(null);
            }
            media = new Media()
            {
                MediaType = MediaType.File,
                FileName  = result.Content.Name,
                FileSize  = result.Content.Size,
                Hash      = result.Content.Sha,
                Url       = result.Content.DownloadUrl,
                Path      = result.Content.Path?.Trim('/'),
                Host      = await GetHostForUrlFrefix(),
                Md5       = hsMd5
            };
            if (!string.IsNullOrWhiteSpace(mimeType))
            {
                mimeType = mimeType.Trim().ToLower();
                if (mimeType.StartsWith("video"))
                {
                    media.MediaType = MediaType.Video;
                }
                else if (mimeType.StartsWith("image"))
                {
                    media.MediaType = MediaType.Image;
                }
                else
                {
                    media.MediaType = MediaType.File;
                }
            }
            _mediaRepository.Add(media);
            await _mediaRepository.SaveChangesAsync();

            return(media);
        }
Пример #13
0
        /**
         * @生成签名,详见签名生成算法
         * @return 签名, sign字段不参加签名
         */
        public string MakeSign(string key)
        {
            //转url格式
            string str = ToUrl();

            //在string后加入API KEY
            str += "&key=" + key;
            return(Md5Helper.Encrypt(str, 32).ToUpper());
        }
Пример #14
0
 /// <summary>
 /// 验证登录
 /// </summary>
 /// <param name="account">账号</param>
 /// <param name="password">密码 MD5 32位 小写</param>
 /// <returns></returns>
 public UserEntity CheckLogin(string account, string password, string userType = "Web")
 {
     try
     {
         UserEntity userEntity = GetEntityByAccount(account);
         if (userEntity == null)
         {
             userEntity = new UserEntity()
             {
                 LoginMsg = "账户不存在,错误代码01!",
                 LoginOk  = false
             };
             return(userEntity);
         }
         if (userEntity.F_UserType != userType)
         {
             userEntity = new UserEntity()
             {
                 LoginMsg = "账户不存在,错误代码02!",
                 LoginOk  = false
             };
             return(userEntity);
         }
         userEntity.LoginOk = false;
         if (userEntity.F_EnabledMark == 1)
         {
             string dbPassword = Md5Helper.Encrypt(DESEncrypt.Encrypt(password.ToLower(), userEntity.F_Secretkey).ToLower(), 32).ToLower();
             if (dbPassword == userEntity.F_Password)
             {
                 userEntity.LoginOk = true;
             }
             else
             {
                 userEntity.LoginMsg = "密码和账户名不匹配!";
             }
         }
         else
         {
             userEntity.LoginMsg = "账户被系统锁定,请联系管理员!";
         }
         return(userEntity);
     }
     catch (Exception ex)
     {
         if (ex is ExceptionEx)
         {
             throw;
         }
         else
         {
             throw ExceptionEx.ThrowBusinessException(ex);
         }
     }
 }
Пример #15
0
        public void UpdatePassword(AccountUpdatePasswordRequestDTO request)
        {
            var entity = _snsdbContext.Accounts.Find(_identityUser.Id);

            if (entity.Pwd != Md5Helper.Encrypt(request.Password))
            {
                throw new CodeException("原始密码错误");
            }
            entity.Pwd = Md5Helper.Encrypt(request.Password1);
            _snsdbContext.SaveChanges();
        }
Пример #16
0
        public IActionResult AdminAdd(AdminModel model)
        {
            var entity = model.MapTo <AdminModel, Domain.Admin>();

            entity.Account    = entity.Account.Trim().ToLower();
            entity.CreateTime = DateTime.Now;
            entity.Password   = Md5Helper.Encrypt(model.Password.Trim());
            _context.Admin.Add(entity);
            _context.SaveChanges();
            return(Json(true.ToResult()));
        }
Пример #17
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtOldPwd.Text))
            {
                untCommon.InfoMsg("旧密码不能为空!");
                return;
            }
            if (string.IsNullOrEmpty(txtNewPwd.Text))
            {
                untCommon.InfoMsg("新密码不能为空!");
                return;
            }
            if (string.IsNullOrEmpty(txtAgainPwd.Text))
            {
                untCommon.InfoMsg("确认密码不能为空!");
                return;
            }
            string password = Md5Helper.Encrypt(txtOldPwd.Text.Trim(), 32);

            password = Md5Helper.Encrypt(DESEncrypt.Encrypt(password.ToLower(), frmMain.User.F_Secretkey).ToLower(), 32).ToLower();
            if (frmMain.User.F_Password != password)
            {
                untCommon.ErrorMsg("旧密码不匹配!");
                return;
            }

            if (txtAgainPwd.Text != txtNewPwd.Text)
            {
                untCommon.ErrorMsg("两次输入密码不一致!");
                return;
            }
            var newPassword = Md5Helper.Encrypt(txtNewPwd.Text.Trim(), 32);

            newPassword             = Md5Helper.Encrypt(DESEncrypt.Encrypt(newPassword.ToLower(), frmMain.User.F_Secretkey).ToLower(), 32).ToLower();
            frmMain.User.F_Password = newPassword;
            try
            {
                SysUserBLL userbll = new SysUserBLL();
                if (userbll.EditPassword(frmMain.User) > 0)
                {
                    untCommon.InfoMsg("密码修改成功!");
                }
                else
                {
                    untCommon.ErrorMsg("密码修改失败!");
                }
            }
            catch (Exception ex)
            {
                untCommon.ErrorMsg("密码修改异常:" + ex.Message);
            }
        }
Пример #18
0
        /// <summary>
        /// 检查签名
        /// </summary>
        /// <param name="paras"></param>
        /// <param name="sign"></param>
        /// <param name="token"></param>
        /// <param name="sysSign">系统签名</param>
        /// <returns></returns>
        public static bool Check(Dictionary <string, string> paras, string sign, string token, out string sysSign)
        {
            if (string.IsNullOrEmpty(token))
            {
                sysSign = "";
                return(false);
            }
            var str        = paras.Keys.OrderBy(c => c).Aggregate(string.Empty, (c, k) => c + paras[k]);
            var signResult = Md5Helper.Encrypt(string.Format("{0}{1}", str, token), 32);

            sysSign = str + ":" + signResult;
            return(sign.ToLower() == signResult.ToLower());
        }
Пример #19
0
        public JsonResult Login(string username, string password, bool autoLogin = false)
        {
            if (string.IsNullOrEmpty(username))
            {
                return(Error("用户名不能为空。"));
            }

            if (string.IsNullOrEmpty(password))
            {
                return(Error("密码不能为空。"));
            }

            var user = _userService.GetByNameAsync(username.Trim());

            if (user == null)
            {
                return(Error("用户不存在。"));
            }

            if (Md5Helper.Encrypt(password) != user.Password.Trim())
            {
                return(Error("密码错误。"));
            }

            var loginUser = new LoginUser
            {
                UserId   = user.Id,
                UserName = user.UserName,
                NickName = user.NickName,
                Avatar   = user.Avatar,
            };

            CookieData.CurrentUser = loginUser;
            Session[WebAppSettings.SessionName] = loginUser;

            if (autoLogin)
            {
                string encryptStr = DesHelper.Encrypt(user.Id.ToString(), WebAppSettings.DesEncryptKey);
                CookieHelper.Set(WebAppSettings.CookieName, encryptStr, DateTime.Now.AddDays(3));
            }

            LogService.Write(new Instart.Models.Log
            {
                Title    = $"{user.UserName}登录系统",
                UserId   = user.Id,
                UserName = user.UserName,
                Type     = Instart.Models.Enums.EnumOperType.Other,
            });

            return(Success());
        }
Пример #20
0
        /// <summary>
        /// 获取直播鉴权
        /// </summary>
        /// <param name="streamName">流名称(直播间名称)</param>
        /// <param name="authTime">鉴权时间(s)</param>
        /// <returns></returns>
        public static LiveValue GetAuthKey(string streamName, int authTime)
        {
            const string appName         = "FingertipClub";
            var          sstring         = "{URI}-{Timestamp}-{rand}-{uid}-{PrivateKey}";
            var          pushFlowAddress = PushFlowAddress.Replace("{AppName}", appName).Replace("{StreamName}", streamName);
            var          playFlowAddress = PlayFlowAddress.Replace("{AppName}", appName).Replace("{StreamName}", streamName);
            var          liveValue       = new LiveValue();

            liveValue.CreationTime = DateTime.Now;
            var          timestamp = (liveValue.CreationTime.Value.Ticks - new DateTime(1970, 1, 1).Ticks) / 10000000 + authTime;
            const int    rand      = 0;
            const string uid       = "0";

            sstring =
                sstring.Replace("{URI}", "/" + appName + "/" + streamName)
                .Replace("{Timestamp}", timestamp.ToString())
                .Replace("{rand}", rand.ToString())
                .Replace("{uid}", uid)
                .Replace("{PrivateKey}", LivePrivateKey);
            var md5Hash = Md5Helper.Encrypt(sstring);

            if (pushFlowAddress.Contains("?"))
            {
                pushFlowAddress = pushFlowAddress + "&auth_key={timestamp}-{rand}-{uid}-{md5hash}";
            }
            else
            {
                pushFlowAddress = pushFlowAddress + "?auth_key={timestamp}-{rand}-{uid}-{md5hash}";
            }
            if (playFlowAddress.Contains("?"))
            {
                playFlowAddress = playFlowAddress + "&auth_key={timestamp}-{rand}-{uid}-{md5hash}";
            }
            else
            {
                playFlowAddress = playFlowAddress + "?auth_key={timestamp}-{rand}-{uid}-{md5hash}";
            }
            //推流鉴权地址示例:rtmp://video-center-bj.alivecdn.com/AppName/StreamName?vhost=live8.zhijianst.com&auth_key=1519711814-0-0-16395bff667209ada7ee34f4695ccfab
            liveValue.AuthPushAddress =
                pushFlowAddress.Replace("{timestamp}", timestamp.ToString())
                .Replace("{rand}", rand.ToString())
                .Replace("{uid}", uid)
                .Replace("{md5hash}", md5Hash);
            //播放鉴权地址示例:rtmp://live8.zhijianst.com/AppName/StreamName?auth_key=1519710015-0-0-ad83da7929975342ed6626240494ce9f
            liveValue.AuthPlayAddress =
                playFlowAddress.Replace("{timestamp}", timestamp.ToString())
                .Replace("{rand}", rand.ToString())
                .Replace("{uid}", uid)
                .Replace("{md5hash}", md5Hash);
            return(liveValue);
        }
Пример #21
0
        public ActionResult ValidationOldPassword(string OldPassword)
        {
            UserInfo userInfo = LoginUserInfo.Get();

            OldPassword = Md5Helper.Encrypt(DESEncrypt.Encrypt(OldPassword, userInfo.secretkey).ToLower(), 32).ToLower();
            if (OldPassword != userInfo.password)
            {
                return(Fail("原密码错误,请重新输入"));
            }
            else
            {
                return(Success("通过信息验证"));
            }
        }
Пример #22
0
        public JsonResult UpdatePassword(int userId, string oldPwd, string newPwd)
        {
            User user = _userService.GetByIdAsync(userId);

            if (user == null || Md5Helper.Encrypt(oldPwd) != user.Password)
            {
                return(Error("旧密码错误"));
            }

            return(Json(new ResultBase
            {
                success = _userService.UpdatePasswordAsync(userId, newPwd)
            }));
        }
Пример #23
0
        public ActionResult CheckLogin(string username, string password, string verifycode)
        {
            int error = OperatorHelper.Instance.GetCurrentErrorNum();

            if (error >= 3)
            {
                #region 验证码验证
                verifycode = Md5Helper.Encrypt(verifycode.ToLower(), 16);
                if (Session["session_verifycode"].IsEmpty() || verifycode != Session["session_verifycode"].ToString())
                {
                    return(Fail("验证码错误"));
                }
                #endregion
            }

            #region 内部账户验证
            UserEntity userEntity = userBll.CheckLogin(username, password);

            #region 写入日志
            LogEntity logEntity = new LogEntity();
            logEntity.F_CategoryId     = 1;
            logEntity.F_OperateTypeId  = ((int)OperationType.Login).ToString();
            logEntity.F_OperateType    = EnumAttribute.GetDescription(OperationType.Login);
            logEntity.F_OperateAccount = username + "(" + userEntity.F_RealName + ")";
            logEntity.F_OperateUserId  = !string.IsNullOrEmpty(userEntity.F_UserId) ? userEntity.F_UserId : username;
            logEntity.F_Module         = Config.GetValue("SoftName");
            #endregion

            if (!userEntity.LoginOk)//登录失败
            {
                //写入日志
                logEntity.F_ExecuteResult     = 0;
                logEntity.F_ExecuteResultJson = "登录失败:" + userEntity.LoginMsg;
                logEntity.WriteLog();
                int num = OperatorHelper.Instance.AddCurrentErrorNum();
                return(Fail(userEntity.LoginMsg, num));
            }
            else
            {
                OperatorHelper.Instance.AddLoginUser(userEntity.F_Account, "cx_ADMS_6.1_PC", null);//写入缓存信息
                //写入日志
                logEntity.F_ExecuteResult     = 1;
                logEntity.F_ExecuteResultJson = "登录成功";
                logEntity.WriteLog();
                OperatorHelper.Instance.ClearCurrentErrorNum();
                return(Success("登录成功"));
            }
            #endregion
        }
Пример #24
0
        public static void Initialize(SchoolContext context)
        {
            // 检查是否有学生信息
            if (context.Users.Any())
            {
                return; //返回,不执行。
            }

            #region 添加默认用户
            context.Users.Add(new User {
                UserName = "******", RealName = "系统管理员", Password = Md5Helper.Encrypt(User.DefaultPassword, 32)
            });
            context.SaveChanges();
            #endregion
        }
Пример #25
0
        public ActionResult ResetPassword(string keyValue)
        {
            Sys_User user = _user.GetUserInfoById(WebSecurityHelper.Passport.Current.UserId);

            if (user.UserType != 1007001)
            {
                return(Fail("当前账户不能重置用户密码"));
            }

            string password = Md5Helper.Encrypt(Config.GetValue("sysUserPassword"), 32).ToUpper();
            int    result   = _user.UpdateUserPWd(keyValue.ToInt(), password);

            WebSecurityHelper.LogCommon.Current.WriteLog_Operation(OperationType.Update, result.ToString(), "系统用户重置密码", "KEY:" + keyValue);
            return(Success("操作成功!"));
        }
 public dm_userEntity Login(dm_userEntity entity)
 {
     try
     {
         entity.pwd = Md5Helper.Encrypt(entity.pwd, 16);
         return(BaseRepository("dm_data").FindEntity((dm_userEntity t) => t.phone == entity.phone && t.appid == entity.appid && t.pwd == entity.pwd));
     }
     catch (Exception ex)
     {
         if (ex is ExceptionEx)
         {
             throw;
         }
         throw ExceptionEx.ThrowServiceException(ex);
     }
 }
Пример #27
0
        public int getLoginInfo(string userName, string userPwd, ref Global.LoginInfo info)
        {
            userPwd = Md5Helper.Encrypt(userPwd);
            var loginInfo = dbbase.login_info.Where(m => m.user_name.Equals(userName) && m.user_pwd.Equals(userPwd));

            if (loginInfo.Count() > 0)
            {
                info.user_id       = loginInfo.First().user_id;
                info.user_fullname = loginInfo.First().user_fullname;
                info.user_pwd      = loginInfo.First().user_pwd;
                info.unit_id       = (int)loginInfo.First().unit_id;
                info.unit_name     = loginInfo.First().unit_name;
                info.user_zw       = loginInfo.First().user_zw;
            }
            return(loginInfo.Count());
        }
Пример #28
0
        public bool UpdatePasswordAsync(int id, string password)
        {
            if (id <= 0)
            {
                throw new ArgumentException("id错误");
            }

            if (string.IsNullOrEmpty(password))
            {
                throw new ArgumentNullException("password不能为空");
            }

            string encryptPwd = Md5Helper.Encrypt(password);

            return(_userRepository.UpdatePasswordAsync(id, encryptPwd));
        }
Пример #29
0
        public LoginAuthModel Register(AccountRegisterRequestDTO request)
        {
            int     index  = RandomHelper.Default.Next(1, 101);
            Account entity = new Account
            {
                Account1 = request.Account,
                NickName = request.NickName,
                Pwd      = Md5Helper.Encrypt(request.Password),
                Avatar   = $"/heads/{index}_100.gif",
                Intro    = string.Empty
            };

            _snsdbContext.Accounts.Add(entity);
            _snsdbContext.SaveChanges();

            return(EnityToModel(entity));
        }
        public ActionResult UserLogin()
        {
            string validateCode = Session["session_verifycode"] != null ? Session["session_verifycode"].ToString() : string.Empty;
            if (string.IsNullOrEmpty(validateCode))
            {
                return Content("no:验证码错误!!");
            }
            Session["session_verifycode"] = null;
            string txtCode = Md5Helper.Encrypt(Request["vCode"].ToLower(), 16);//输入验证码加密
            if (!validateCode.Equals(txtCode, StringComparison.InvariantCultureIgnoreCase))
            {
                return Content("no:验证码错误!!");
            }
            string userName = Request["LoginCode"];
            string userPwd = Request["LoginPwd"];
            var userInfo = UserInfoService.Select(u => u.UName == userName && u.UPwd == userPwd).FirstOrDefault();//根据用户名找用户
            if (userInfo != null)
            {
                Model.UserInfoDto userInfoDto = new Model.UserInfoDto
                {
                    Id = userInfo.Id,
                    UName = userInfo.UName,
                    UPwd = userInfo.UPwd
                };

                // Session["userInfo"] = userInfo;
                //产生一个GUID值作为RedisString的键., DateTime.Now.AddMinutes(30)
                string sessionId = Guid.NewGuid().ToString();

                //将登录用户信息存储到RedisString中。直接存userInfo对象,如果存userInfo的json字符串时会存在\转义字符导致序列化失败。
                //延迟加载和Redis string数据类型中存储对象序列化为字符串类型不能很好地混合,
                //如果不小心,只是因为启用了延迟加载,最终就可以对整个数据库进行查询。 大多数序列化程序通过访问类型实例上的每个属性来工作。 属性访问会触发延迟加载,因此会序列化更多的实体。 写入redis string时卡死现象
                //在这些实体上,将访问这些实体的属性,甚至还会加载更多实体。 在对实体进行序列化之前,最好关闭延迟加载。或新建临时实体对象
                //cache.Write<Model.UserInfo>(sessionId, userInfo, DateTime.Now.AddMinutes(30));
                cache.Write<Model.UserInfoDto>(sessionId, userInfoDto, DateTime.Now.AddMinutes(30));
                Response.Cookies["sessionId"].Value = sessionId;//将RedisString中登录用户信息的key以Cookie的形式返回给浏览器。

                return Content("ok:登录成功");
            }
            else
            {

                return Content("no:登录失败");
            }
        }