Example #1
0
        public int ChangeKernelPassword(
            SessionInfo sessioninfo,
            string strOldPassword,
            string strNewPassword,
            out string strError)
        {
            strError = "";

            // 验证旧密码是否符合 library.xml 中的定义
            if (strOldPassword != this.ManagerPassword)
            {
                strError = "旧密码不吻合。修改 kernel 密码失败";
                return(-1);
            }

            RmsChannel channel = sessioninfo.Channels.GetChannel(this.WsUrl);

            if (channel == null)
            {
                strError = "get channel error";
                return(-1);
            }

            //		value == -1 出错
            //				 0  用户名或密码不正确
            //				 1  成功
            int nRet = channel.Login(this.ManagerUserName,
                                     strOldPassword,
                                     out strError);

            if (nRet == -1)
            {
                strError = "登录 dp2kernel 失败:" + strError;
                return(-1);
            }
            if (nRet == 0)
            {
                strError = "旧密码和 dp2kernel 帐户不吻合。修改 kernel 密码失败";
                return(-1);
            }

            // return:
            //		-1	出错。错误信息在strError中
            //		0	成功。
            nRet = channel.ChangePassword(this.ManagerUserName,
                                          strOldPassword,
                                          strNewPassword,
                                          false,
                                          out strError);
            if (nRet == -1)
            {
                strError = "在 dp2kernel 中修改密码失败:" + strError;
                return(-1);
            }

            this.ManagerPassword = strNewPassword;
            this.Changed         = true;
            return(0);
        }
Example #2
0
        private void button_OK_Click(object sender, System.EventArgs e)
        {
            if (textBox_url.Text == "")
            {
                MessageBox.Show(this, "尚未指定服务器URL...");
                return;
            }

            if (textBox_newPassword.Text != textBox_newPasswordConfirm.Text)
            {
                MessageBox.Show(this, "新密码和确认密码不一致,请重新输入...");
                return;
            }

            if (textBox_userName.Text == "")
            {
                MessageBox.Show(this, "尚未输入用户名。");
                return;
            }

            channel = Channels.GetChannel(textBox_url.Text);
            Debug.Assert(channel != null, "Channels.GetChannel 异常");

            stop.OnStop += new StopEventHandler(this.DoStop);
            stop.Initial("正在修改密码...");

            stop.BeginLoop();

            int    nRet;
            string strError;

            EnableControls(false);
            button_Cancel.Text = "中断";


            nRet = channel.ChangePassword(
                textBox_userName.Text,
                textBox_oldPassword.Text,
                textBox_newPassword.Text,
                checkBox_manager.Checked,
                out strError);

            EnableControls(true);

            stop.EndLoop();

            stop.OnStop -= new StopEventHandler(this.DoStop);
            stop.Initial("");

            button_Cancel.Enabled = true;       // 因为Cancel按钮还有退出对话框的功能
            button_Cancel.Text    = "取消";

            if (nRet == -1)
            {
                goto ERROR1;
            }

            channel = null;

            MessageBox.Show(this, "密码修改成功。");

            this.DialogResult = DialogResult.OK;
            this.Close();
            return;

ERROR1:
            button_Cancel.Enabled = true;
            button_Cancel.Text    = "取消";

            channel = null;
            MessageBox.Show(this, "修改密码失败,原因:" + strError);
        }