Exemple #1
0
        public static Boolean CreateResetPassword(ResetPwd Pwd)
        {
            Boolean flag = false;

            if (UpdateExistResetPassword(Pwd))
            {

                using (TransactionScope scope = new TransactionScope())
                {
                    using (var context = new SycousCon())
                    {
                        try
                        {
                            context.ResetPwds.AddObject(Pwd);
                            context.SaveChanges();
                            scope.Complete();
                            context.AcceptAllChanges();
                            flag = true;
                        }
                        catch (Exception ex)
                        {
                            context.Dispose();
                            throw;
                        }
                    }
                }
            }
            return flag;
        }
Exemple #2
0
        public static bool UpdateExistResetPassword(ResetPwd Pwd)
        {
            Boolean flag = true;
            using (TransactionScope scope = new TransactionScope())
            {
                using (var context = new SycousCon())
                {
                    try
                    {
                        var ResetToUpdate = context.ResetPwds.Where(c => c.UserID == Pwd.UserID && c.Active == false);
                        foreach (ResetPwd p in ResetToUpdate)
                        {
                            p.Active = true;
                            p.ModifyBy = Pwd.CreateBy;
                            p.ModifyDate = DateTime.Now;
                        }

                        context.SaveChanges();
                        context.AcceptAllChanges();
                        scope.Complete();
                        context.Dispose();
                        flag = true;
                    }
                    catch (Exception ex)
                    {
                        flag = false;
                        context.Dispose();
                        throw;
                    }
                }
            }
            return flag;
        }
Exemple #3
0
        public Boolean AddRecord(Object objPwd)
        {
            Boolean flag = false;
            ForgotPwd PWD = (ForgotPwd)objPwd;
            try
            {
                ResetPwd _PWD = new ResetPwd();
                if (PWD.UserID != null)
                {
                    _PWD.UserID = PWD.UserID;
                }
                if (PWD.CreateBy != null)
                {
                    _PWD.CreateBy = Convert.ToInt64(PWD.CreateBy);
                }
                if (PWD.ResetIpAddress != null)
                {
                    _PWD.ResetIpAddress = PWD.ResetIpAddress;
                }
                _PWD.CreateDate = DateTime.Now;
                _PWD.Active = false;

                if (_PWD.UserID != null)
                {
                    flag = DAL.DALUserPwdRest.CreateResetPassword(_PWD);
                }
            }
            catch (Exception ex)
            {
                throw;
            }

            return flag;
        }
        public JsonResult ResetPassword(string active, ResetPwd resetPwd)
        {
            var data = new { code = 1, msg = "修改失败" };

            if (!string.IsNullOrEmpty(active) && ModelState.IsValid)
            {
                if (TempData[Keys.ValidCode] == null || !TempData[Keys.ValidCode].ToString().Equals(resetPwd.Code, StringComparison.CurrentCultureIgnoreCase))
                {
                    data = new { code = 1, msg = "验证码错误" };
                    //Session[Keys.ValidCode] = null;
                    return(Json(data));
                }
                var obj = MemcacheHelper.Get(active);
                if (obj != null)
                {
                    var user = SerializerHelper.DeserializeToObject <User>(obj.ToString());
                    if (user != null)
                    {
                        user.Login_Password = resetPwd.Password.Md5_32();
                        userService.EditEntity(user);
                        if (userService.SaveChanges())
                        {
                            data = new { code = 0, msg = "修改成功,请牢记新密码。" };
                            MemcacheHelper.Set(active, null, DateTime.Now.AddHours(-1));
                        }
                    }
                }
            }
            return(Json(data));
        }
        /// <summary>
        /// 找回密码模板
        /// </summary>
        /// <returns></returns>
        public ActionResult PwdReSetTemplate()
        {
            ResetPwd resetpwdEntry = new ResetPwd
            {
                UserId         = (int)1,
                ModifyPwdToken = Utils.GuId(),
                PwdCodeTme     = DateTime.Now,
                ModfiyPwdCode  = Utils.RndNum(6),
                LoginName      = "admin",
                NickName       = "、天上有木月"
            };

            return(View(resetpwdEntry));
        }
Exemple #6
0
 public WebSocketApi(string uri)
 {
     _client        = new Client(uri);
     _login         = new Login(_client);
     _changePwd     = new ChangePwd(_client);
     _forgotPwd     = new ForgotPwd(_client);
     _resetPwd      = new ResetPwd(_client);
     _validMail     = new ValidMail(_client);
     _register      = new Register(_client);
     _getFriends    = new GetFriends(_client);
     _getPFriends   = new GetPendingFriends(_client);
     _removeFriend  = new RemoveFriend(_client);
     _addFriend     = new AddFriend(_client);
     _confirmFriend = new ConfirmFriend(_client);
 }
Exemple #7
0
        private void btnReset_Click(object sender, EventArgs e)
        {
            string name = (string)this.listBox1.SelectedItem;

            if (name != null)
            {
                UserDialogBase f = new ResetPwd(name);
                f.ShowDialog();

                if (f.DialogResult == DialogResult.OK)
                {
                    UserManager.ResetPassword(f.Username, f.Password);
                    RefreshList();
                }
            }
        }
        public WebSocketApi(string uri)
        {
            _client = new Client(uri);
            var dataExchange = new DataExchange(_client);

            _login         = new Login(dataExchange);
            _changePwd     = new ChangePwd(dataExchange);
            _forgotPwd     = new ForgotPwd(dataExchange);
            _resetPwd      = new ResetPwd(dataExchange);
            _validMail     = new ValidMail(dataExchange);
            _register      = new Register(dataExchange);
            _getFriends    = new GetFriends(dataExchange);
            _getPFriends   = new GetPendingFriends(dataExchange);
            _removeFriend  = new RemoveFriend(dataExchange);
            _addFriend     = new AddFriend(dataExchange);
            _confirmFriend = new ConfirmFriend(dataExchange);
            _logger        = LoggerFactory.GetLogger();
        }
        public AjaxResult ResetPwd(string pwdtoken, string account, string newpwd, string emailcode)
        {
            AjaxResult amm;

            var userEntity = this.Queryable(u => u.Email == account).FirstOrDefault();

            if (userEntity != null)
            {
                //从缓存中取出存放的验证码的键(邮箱+"sendcodekey")得到重置密码的对象
                ResetPwd rpwdEntry = _iRedisHelper.StringGet <ResetPwd>(account + "sendcodekey");

                if (rpwdEntry != null && rpwdEntry.ModifyPwdToken == pwdtoken)
                {
                    if (rpwdEntry.ModfiyPwdCode != emailcode)
                    {
                        amm = AjaxResult.Error("验证码不正确!");
                    }
                    else
                    {
                        string cacheaccount = _iRedisHelper.StringGet <string>(account + "modfiyPwdKey");
                        if (!string.IsNullOrEmpty(cacheaccount))
                        {
                            amm = AjaxResult.Error("10分钟内只可修改一次密码,请稍后再试!");
                        }
                        else
                        {  //重置密码成功之后将帐号写入cache中,10分钟内只可修改一次密码
                            ResetPassword(userEntity, newpwd);
                            amm = AjaxResult.Success("重置密码成功!");

                            _iRedisHelper.StringSet <string>(account + "modfiyPwdKey", account, new TimeSpan(0, 10, 0));
                        }
                    }
                }
                else
                {
                    amm = AjaxResult.Error("验证码过期了!");
                }
            }
            else
            {
                amm = AjaxResult.Error("此帐号尚未注册");
            }
            return(amm);
        }
Exemple #10
0
 public IActionResult Reset(ResetPwd reset)
 {
     if (ModelState.IsValid)
     {
         var model = _repositoryEF.Find(reset.Id);
         if (model == null)
         {
             return(Json(new { Data = false }));
         }
         else
         {
             model.Encrypt  = Cryptographer.CreateSalt();
             model.Password = Cryptographer.EncodePassword(reset.Pwd, 1, model.Encrypt);
             _repositoryEF.Update(model);
             _unitOfWork.Commit();
             return(Json(new { Data = true }));
         }
     }
     return(Json(new { Data = false }));
 }
        public AjaxResult SmsCode(string email)
        {
            AjaxResult amm;
            int        limitcount   = 10;
            int        limitMinutes = 10;

            if (!Validate.IsEmail(email))
            {
                return(AjaxResult.Error("邮箱格式不正确"));
            }

            AppUser userEntity = this.Queryable(u => u.Email == email && u.DeleteMark == false).FirstOrDefault();

            if (userEntity == null)
            {
                amm = AjaxResult.Error("此邮箱尚未注册!");
            }
            else
            {
                string count = _iRedisHelper.StringGet <string>(email);
                //缓存十分钟,如果缓存中存在,且请求次数超过10次,则返回
                if (!string.IsNullOrEmpty(count) && Convert.ToInt32(count) >= limitcount)
                {
                    amm = AjaxResult.Error("没收到邮箱:请联系[email protected]");
                }
                else
                {
                    #region 发送邮箱,并写入缓存,更新登录信息表的token,date,code
                    int num = 0;
                    if (!string.IsNullOrEmpty(count))
                    {
                        num = Convert.ToInt32(count);
                    }
                    string countplus1 = num + 1 + "";
                    _iRedisHelper.StringSet <string>(email, countplus1, new TimeSpan(0, limitMinutes, 0));

                    ResetPwd resetpwdEntry = new ResetPwd
                    {
                        UserId         = (int)userEntity.Id,
                        ModifyPwdToken = Utils.GuId(),
                        PwdCodeTme     = DateTime.Now,
                        ModfiyPwdCode  = Utils.RndNum(6),
                        LoginName      = userEntity.LoginName,
                        NickName       = userEntity.NickName
                    };

                    //将发送验证码的数据存入redis缓存中

                    _iRedisHelper.StringSet(email + "sendcodekey", resetpwdEntry, new TimeSpan(0, limitMinutes, 0));
                    //发送找回密码的邮件

                    string body = UiHelper.FormatEmail(resetpwdEntry, "PwdReSetTemplate");
                    _imailHelper.SendByThread(email, "[、天上有木月博客] 密码找回", body);

                    #endregion
                    //将修改密码的token返回给前端
                    amm = AjaxResult.Info("验证码已发送至你的邮箱!", resetpwdEntry.ModifyPwdToken, ResultType.Success.ToString());
                }
            }
            return(amm);
        }
Exemple #12
0
        public IActionResult ResetPwd(ResetPwd reset)
        {
            if (!ModelState.IsValid)
            {
                ViewData["Message"] = "Invalid Input";
                ViewData["MsgType"] = "warning";
                return(View("ResetPassword"));
            }
            else
            {
                string Username    = reset.Username.ToString();
                string currentpwd  = reset.currentPwd.ToString();
                string password    = reset.UserPw.ToString();
                string cfmpassword = reset.UserPw2.ToString();
                string sql         = @"SELECT * FROM Users WHERE Username='******'";
                Console.WriteLine(sql);
                string select = String.Format(sql, Username);
                Console.WriteLine("select");
                DataTable dt = DBUtl.GetTable(select);
                foreach (DataRow row in dt.Rows)
                {
                    string uname    = row.Field <string>("Username");
                    byte[] Password = row.Field <byte[]>("Password");
                    SHA1   currentpwd_hashed_obj = SHA1.Create();
                    byte[] currentpwd_bytes      = Encoding.UTF8.GetBytes(currentpwd);
                    byte[] currentpwd_hashed     = currentpwd_hashed_obj.ComputeHash(currentpwd_bytes);

                    bool bEqual = false;
                    if (Password.Length == currentpwd_hashed.Length)
                    {
                        int i = 0;
                        while ((i < Password.Length) && (Password[i] == currentpwd_hashed[i]))
                        {
                            i += 1;
                        }
                        if (i == Password.Length)
                        {
                            bEqual = true;
                        }
                    }

                    if (bEqual)
                    {
                        if (password.Equals(cfmpassword))
                        {
                            string update = @"UPDATE Users SET Password=HASHBYTES('SHA1','{2}') WHERE Username = '******'";
                            Console.WriteLine(update);
                            int res = DBUtl.ExecSQL(update, uname, currentpwd, cfmpassword);
                            Console.WriteLine(res);
                            if (res == 1)
                            {
                                ViewData["Message"] = "Password has been reset successfully.";
                                ViewData["MsgType"] = "success";
                                return(View("ResetPassword"));
                            }
                            else
                            {
                                ViewData["Message"] = "Password reset unsuccessful.";
                                ViewData["MsgType"] = "warning";
                                return(View("ResetPassword"));
                            }
                        }
                        else
                        {
                            ViewData["Message"] = "Confirmed password does not match with the new password.";
                            ViewData["MsgType"] = "danger";
                            return(View("ResetPassword"));
                        }
                    }
                    else
                    {
                        ViewData["Message"] = "Current password does not match with the previous password.";
                        ViewData["MsgType"] = "warning";
                    }
                }
            }
            return(View("ResetPassword"));
        }