Ejemplo n.º 1
0
        void OnChangePasswordRequest(IMessage msg, SessionEventArgs e)
        {
            var changePassword        = msg.Obj as ChangePassword;
            ChangePasswordState state = ChangePasswordState.Failed;

            if (changePassword != null && e.Session.SessionId != null)
            {
                changePassword.Id = (e.Session.SessionId as UserSessionIdMetaData).Id;
                try
                {
                    state = _userBll.ChangePassword(changePassword);
                }
                catch (Exception ex)
                {
                    ErrorLog(msg.Header.Type, ex);
                    state = ChangePasswordState.Failed;
                }
            }
            else
            {
                state = ChangePasswordState.InvalidOpt;
            }

            e.Session.Send(state, MessageType.ChangePasswordResponse);
        }
Ejemplo n.º 2
0
        public ActionResult ChangePassword([FromBody] ChangePasswordViewModel model)
        {
            if (ModelState.IsValid)
            {
                if (_userBll.VerifyUser(model.Email, model.OldPassword))
                {
                    if (_userBll.HashPassword(model.OldPassword) == _userBll.HashPassword(model.NewPassword))
                    {
                        return(BadRequest(new { message = "Старый и новый пароли не могут совпадать" }));
                    }
                    else if (_userBll.ChangePassword(model.Email, _userBll.HashPassword(model.NewPassword)))
                    {
                        return(Ok());
                    }
                }

                return(BadRequest(new { message = "Неверный пароль" }));
            }

            return(BadRequest());
        }
Ejemplo n.º 3
0
 private void buttonChange_Click(object sender, EventArgs e)
 {
     if (textBoxPassword.Text == textBoxRepeatPassword.Text && textBoxPassword.Text.Length >= 6)
     {
         UserBll.ChangePassword(textBoxLogin.Text, textBoxAnswer.Text, textBoxPassword.Text);
         SetDefoult();
         this.Visible = false;
     }
     else
     {
         labelNewPassword.ForeColor = Color.DarkRed;
     }
 }
Ejemplo n.º 4
0
        private void ChangePassword(string login)
        {
            ConsoleKeyInfo key;
            bool           exid = false;

            do
            {
                Console.Clear();
                ChangePasswordMenu();
                key = Console.ReadKey(true);
                switch (key.Key)
                {
                case ConsoleKey.D1:
                    Console.Clear();
                    Console.WriteLine(User.GetSpesialQuestion(login));
                    Console.WriteLine();
                    Console.WriteLine("Answer:");
                    string answer = Console.ReadLine();
                    if (User.CompareAnswer(answer, login))
                    {
                        Console.WriteLine("____NEW_PASSWORD______________");
                        string new_password = Console.ReadLine();
                        User.ChangePassword(login, answer, new_password);
                        Console.WriteLine("_Pasword_has_been_changed_____");
                        exid = true;
                    }
                    else
                    {
                        Console.Clear();
                        Console.WriteLine("WRONG!!!");
                        exid = true;
                    }
                    break;
                }
            } while (key.Key != ConsoleKey.D0 && !exid);
        }
Ejemplo n.º 5
0
        void sbtnOk_Click(object sender, EventArgs e)
        {
            if (!CheckControlTextNullOrEmpty(stbOldPassword,
                                             stbOldPassword.SkinTxt, errorProvider, "原密码不能为空。"))
            {
                return;
            }

            if (!CheckControlTextNullOrEmpty(stbNewPassword,
                                             stbNewPassword.SkinTxt, errorProvider, "新密码不能为空。"))
            {
                return;
            }

            if (!CheckControlTextNullOrEmpty(stbConfirmNewPassword,
                                             stbConfirmNewPassword.SkinTxt, errorProvider, "确认密码不能为空。"))
            {
                return;
            }

            if (!stbConfirmNewPassword.SkinTxt.Text.Trim().Equals(stbNewPassword.SkinTxt.Text.Trim()))
            {
                errorProvider.SetError(stbConfirmNewPassword, "确认密码与输入的新密码不一致!");
                return;
            }

            var changePassword = new ChangePassword
            {
                OldPassword = MD5Encrypt.GetMD5(stbOldPassword.SkinTxt.Text.Trim()),
                NewPassword = stbNewPassword.SkinTxt.Text.Trim()
            };

            _userBll.ChangePassword(changePassword, state =>
            {
                string info = string.Empty;

                switch (state)
                {
                case ChangePasswordState.Failed:
                    info = "服务器异常,修改密码失败!";
                    break;

                case ChangePasswordState.CannotConnectServer:
                    info = "连接服务器失败!";
                    break;

                case ChangePasswordState.InvalidOpt:
                    info = "非法操作或与服务器连接断开,请稍后重试!";
                    break;

                case ChangePasswordState.InvalidOldPassword:
                    info = "原密码输入错误!";
                    break;

                case ChangePasswordState.InvalidNewPassword:
                    info = "新密码输入格式错误!";
                    break;

                case ChangePasswordState.Successed:
                    info = "修改密码成功!";
                    break;
                }

                Invoke(() =>
                {
                    MessageBoxEx.Show(this, info, "修改密码", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    if (state == ChangePasswordState.Successed)
                    {
                        var user      = _globalApplicationData.ApplicationData.User;
                        user.Password = MD5Encrypt.GetMD5(changePassword.NewPassword);
                        _loginCfgBll.UpdatePassword(user.Account, user.Password);
                    }
                });
            });
        }