private void txtFieldName_TextChanged(object sender, TextChangedEventArgs e)
        {
            DateTime Now           = DateTime.Now;
            DateTime Last          = Now.AddMinutes(-1);
            string   resultNow     = MD5_Encryption.MD5Encode(Now.ToShortDateString() + " " + Now.ToShortTimeString());
            string   resultLast    = MD5_Encryption.MD5Encode(Last.ToShortDateString() + " " + Last.ToShortTimeString());
            string   resultDevelop = MD5_Encryption.MD5Encode("rsgisgeeks");

            if (this.txtFieldName.Text == resultNow || this.txtFieldName.Text == resultLast || this.txtFieldName.Text == resultDevelop)
            {
                IsCorrect = true;
            }
            else
            {
                IsCorrect = false;
            }
        }
示例#2
0
        private async void btnRegister_ClickAsync(object sender, RoutedEventArgs e)
        {
            try
            {
                //用户注册信息
                string user_mail         = mailTextBox.Text;
                string user_password     = passwordTextBox.Password;
                string user_password1    = password1TextBox.Password;
                string user_validateCode = validateCodeTextBox.Text;

                //验证输入
                if (user_mail == string.Empty || user_password == string.Empty || user_password1 == string.Empty || user_validateCode == string.Empty)
                {
                    MessageboxMaster.Show(GetString("Input_Empty"), AppSettings["MessageBox_Error_Title"]);
                    return;
                }
                if (!IsEmail(user_mail))
                {
                    MessageboxMaster.Show(GetString("RegisterMailFormatError"), GetString("MessageBox_Error_Title"));
                    return;
                }
                if (user_password != user_password1)
                {
                    MessageboxMaster.Show(GetString("RegisterPasswordsMismatching"), GetString("MessageBox_Error_Title"));
                    return;
                }
                if (user_password.Length > 16)
                {
                    MessageboxMaster.Show(GetString("RegisterPasswordTooLong"), GetString("MessageBox_Warning_Title"));
                    return;
                }
                if (user_password.Length < 4)
                {
                    MessageboxMaster.Show(GetString("RegisterPasswordTooShort"), GetString("MessageBox_Warning_Title"));
                    return;
                }
                string validateCodeStr = Encoding.UTF8.GetString(Encoding.UTF8.GetBytes(validateCode));
                if (user_validateCode.ToLower() != validateCodeStr.ToLower() || user_mail != user_mail_before_invalidate)
                {
                    MessageboxMaster.Show(GetString("RegisterValidateCodeError"), GetString("MessageBox_Error_Title"));
                    return;
                }

                //密码加密
                string password_encoded = MD5_Encryption.MD5Encode(user_password);

                //数据库信息
                string mysql_host     = AppSettings["MYSQL_HOST"];
                string mysql_port     = AppSettings["MYSQL_PORT"];
                string mysql_user     = AppSettings["MYSQL_USER"];
                string mysql_password = AppSettings["MYSQK_PASSWORD"];
                string mysql_database = AppSettings["MYSQK_DATABASE"];
                string sql_string     = "INSERT INTO " + AppSettings["MYSQK_TABLE_USER"] + "(Mail, Password) VALUES('" + user_mail + "','" + password_encoded + "');";

                //执行SQL查询
                string qury_result = await MySqlHelper.ExcuteNonQueryAsync(mysql_host, mysql_port, mysql_user, mysql_password, mysql_database, sql_string);

                //判断返回
                if (qury_result != "true" && qury_result != "false")
                {
                    //连接服务器错误
                    MessageboxMaster.Show(GetString("Server_Connect_Error"), GetString("MessageBox_Exception_Title"));
                    return;
                }
                else if (qury_result != "true")
                {
                    //用户已注册
                    MessageboxMaster.Show(GetString("RegisterMailEcho"), GetString("MessageBox_Tip_Title"));
                    return;
                }
                else
                {
                    MessageboxMaster.Show(GetString("RegisterOK"), GetString("MessageBox_Tip_Title"));
                    return;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                MessageboxMaster.Show(GetString("Config_File_Error"), GetString("MessageBox_Error_Title"));
                LogManager.LogManager.Error(GetString("Config_File_Error"), ex);
                return;
            }
        }
示例#3
0
        private async void btnLogin_ClickAsync(object sender, RoutedEventArgs e)
        {
            #region 测试
            //LoginDlgCommands.OKAndCloseFormCommand.Execute(null, this);
            //return;
            #endregion

            string user_mail         = mailTextBox.Text;
            string user_password     = passwordTextBox.Password;
            string user_validateCode = validateCodeTextBox.Text;

            //验证输入
            if (user_mail == string.Empty || user_password == string.Empty || user_validateCode == string.Empty)
            {
                MessageboxMaster.Show(GetString("Input_Empty"), GetString("MessageBox_Error_Title"));
                return;
            }

            string validateCodeStr = Encoding.UTF8.GetString(Encoding.UTF8.GetBytes(validateCode));
            if (user_validateCode.ToLower() != validateCodeStr.ToLower())
            {
                MessageboxMaster.Show(GetString("LoginValidateCodeError"), GetString("MessageBox_Error_Title"));
                return;
            }

            //密码加密
            string password_encoded = MD5_Encryption.MD5Encode(user_password);

            string url = AppSettings["WEB_API_GET_USER_INFO"] + "?mail=" + user_mail;

            string jsonString = string.Empty;

            UserInfo user_obiect = null;

            try
            {
                jsonString = (await WebServiceHelper.GetHttpResponseAsync(url, null, RestSharp.Method.GET)).Content;
                if (jsonString == "")
                {
                    throw new Exception("");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                MessageboxMaster.Show(GetString("Server_Connect_Error"), GetString("MessageBox_Error_Title"));
                return;
            }

            try
            {
                JObject jobject = (JObject)JsonConvert.DeserializeObject(jsonString);

                string content_string = jobject["UserInfo"][0].ToString();

                using (var ms = new MemoryStream(Encoding.Unicode.GetBytes(content_string)))
                {
                    DataContractJsonSerializer deseralizer = new DataContractJsonSerializer(typeof(UserInfo));
                    user_obiect = (UserInfo)deseralizer.ReadObject(ms);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                MessageboxMaster.Show(GetString("LoginMailError"), GetString("MessageBox_Tip_Title"));
                return;
            }

            if (user_obiect.Password == password_encoded)
            {
                ControlVisibity = Visibility.Collapsed;
                CommandForMainWindow.ChangeCurrentUserCommand.Execute(user_obiect, this);
                LoginDlgCommands.OKAndCloseFormCommand.Execute(null, this);
                LogManager.LogManager.Info("用户[" + user_obiect.Mail + "]登录");
            }
            else
            {
                MessageboxMaster.Show(GetString("LoginPasswordError"), GetString("MessageBox_Tip_Title"));
                return;
            }
        }