Ejemplo n.º 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            string[] auth = { "NULL", "NULL" };
            if (username.Text == "")
            {
                MessageBox.Show("请输入用户名!");
            }
            else
            {
                if (passwd.Text == "")
                {
                    MessageBox.Show("请输入密码!");
                }
                else
                {
                    byte[] tempData;
                    tempData = Encoding.ASCII.GetBytes(username.Text);

                    User.UserConfig.username = System.Convert.ToBase64String(tempData);
                    if (passwd.Text != "UseSavedPasswd!")
                    {
                        MD5 md5Hash = MD5.Create();
                        tempData = Encoding.ASCII.GetBytes(passwd.Text);
                        User.UserConfig.passwd = User.GetMd5Hash(md5Hash, System.Convert.ToBase64String(tempData));
                    }

                    User.login(User.UserConfig.username, User.UserConfig.passwd);
                    ServerConfig ServerCfg = new ServerConfig();
                    switch (User.UserStatus.status)
                    {
                    case "0":
                        this.Text = "登录成功!";
                        Program prog         = new Program();
                        bool    ConfigResult = ServerCfg.Get(Application.StartupPath + "\\gui-config.json", Program.version, Program.macAddress);
                        if (ConfigResult == false)
                        {
                            MessageBox.Show("无法连接服务器获取配置,请检查您的网络连接!\r\n1、网络连接是否正常\r\n2、DNS设置是否正常\r\n3、IE代理是否正常(请取消一切代理选项)");
                            Environment.Exit(0);
                        }
                        int a = prog.start();
                        User.UserConfig.SaveConfig();
                        this.Hide();
                        break;

                    case "1":
                        MessageBox.Show("登录失败,请检查您的用户名和密码!");
                        break;

                    case "-1":

                        break;

                    default:
                        MessageBox.Show("登录失败,未知错误");
                        break;
                    }
                }
            }
        }