Пример #1
0
        private void Login()
        {
            bool isBusy   = false;
            bool finished = false;

            while (!finished)
            {
                Console.WriteLine(" request    ");
                if (AppClient.IsReady)
                {
                    AppSetting.RECONN_USER = txtusername.Text.Trim();
                    string  pwd    = txtuserpwd.Text.Trim();
                    ICrypta crypta = SecurityService.GetCrypta();
                    pwd = crypta.specialEncrypt(pwd);
                    AppSetting.RECONN_PWD = pwd;
                    string cpuSN       = SysUtil.GetSpecialStuffValueInfo(Win32Stuff.Win32_Processor.ToString(), "ProcessorId");
                    string hdID        = SysUtil.GetSpecialStuffValueInfo(Win32Stuff.Win32_DiskDrive.ToString(), "Model");
                    string machineInfo = cpuSN + "-" + hdID;
                    machineInfo = machineInfo ?? (LoginHandler.NULL);
                    machineInfo = string.IsNullOrEmpty(machineInfo.Trim()) ? LoginHandler.NULL : machineInfo.Trim();

                    AppSetting.MACHINE_INFO = machineInfo;
                    string request = NetHelper.BuildMsg(Protocol.C0001_1, new string[] { txtusername.Text.Trim(), pwd, machineInfo, AppSetting.VERSION, AppSetting.A_OR_C });
                    crypta = null;
                    Console.WriteLine(" request    " + count);
                    try
                    {
                        loginHandler.Send(request);
                        finished = true;
                    }
                    catch (Exception ex)
                    {
                        this.Invoke(new MethodInvoker(Noconnection));
                    }
                }

                count++;
                if (count >= MAX_LOGIN_TIME)
                {
                    AppClient.Close();
                    AppClient.IsStopAttempt = true;
                    isBusy = true;
                    break;
                }
                Thread.Sleep(500);
                if (isCancel)
                {
                    break;
                }
            }

            if (isBusy == true && !isCancel)
            {
                this.Invoke(new MethodInvoker(Noconnection));
            }
        }
 private void btnReset_Click(object sender, EventArgs e)
 {
     if (AppClient.IsReady)
     {
         ICrypta crypta = SecurityService.GetCrypta();
         if (string.IsNullOrEmpty(textOldPwd.Text) && string.IsNullOrEmpty(textNewPwd.Text) && string.IsNullOrEmpty(textConfirmPwd.Text))
         {
             MessageBox.Show(this, "Passwords can not be empty!", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
         else if (textNewPwd.Text.Trim() != textConfirmPwd.Text)
         {
             MessageBox.Show(this, "Re-type password is not the same as new password.", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
         else if (crypta.specialEncrypt(textOldPwd.Text.Trim()) != AppSetting.PWD)
         {
             MessageBox.Show(this, "Old password is incorrect, please try again! ", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
         else if (textNewPwd.Text.Length < 6)
         {
             MessageBox.Show(this, "Password must be at least 8 characters, please try again. ", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
         else if (!AppUtil.PwdIsValid(textNewPwd.Text.Trim()))
         {
             MessageBox.Show(this, "Password cannot be any triple repeat characters, please try again. ", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
         else
         {
             //string oldPwd = textOldPwd.Text.Trim();
             string newPwd = textNewPwd.Text.Trim();
             //oldPwd = crypta.specialEncrypt(oldPwd);
             newPwd = crypta.specialEncrypt(newPwd);
             string request = NetHelper.BuildMsg(Protocol.C0001_2, new string[] { AppSetting.PWD, newPwd });
             Console.WriteLine(" request    " + request);
             resetPwdHandler.Send(request);
         }
         crypta = null;
     }
     else
     {
         MessageBox.Show(this, "Network is disconnected!", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }