Beispiel #1
0
        public void UpdatePassword(FormCollection collection)
        {
            var msg  = new Msg();
            var User = new Users();
            var user = User.FindById((int)Session["id"]);

            try
            {
                var pwd_old = collection["pwd_old"];
                var pwd_new = collection["pwd_new"];
                var Utils   = new Utils.Utils();
                // 验证原密码
                if (Utils.CheckPasswd(pwd_old, user.User_pwd))
                {
                    user.User_pwd = Utils.HashBcrypt(pwd_new);
                    if (User.Update(user))
                    {
                        msg.Message = "修改密码成功,下次登录时请使用新密码登录";
                    }
                    else
                    {
                        throw new Exception("发生未知错误");
                    }
                }
                else
                {
                    throw new Exception("原密码输入有误");
                }
            }
            catch (Exception ex)
            {
                msg.Code    = -1;
                msg.Message = ex.Message;
            }
            Response.Write(msg.ToJson());
            Response.End();
        }
Beispiel #2
0
        // GET: Tools
        public ActionResult Index()
        {
            var hash  = Request["hash"];
            var txt   = Request["txt"];
            var Utils = new Utils.Utils();

            if (hash != null && hash.Length > 20)
            {
                Response.Write(Utils.CheckPasswd(txt, hash) ? true : false);
                Response.End();
            }
            if (txt != null && txt.Length > 0)
            {
                var msg = new Msg();
                msg.Content = new
                {
                    text        = txt,
                    bcrypt_hash = Utils.HashPassword(txt),
                };
                Response.Write(msg.ToJson());
                Response.End();
            }
            return(View());
        }