Esempio n. 1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            string path = @"ClientsIdentification.stg";
            string data = "";

            if (tbAddress.Text.Trim().Length > 0)
            {
                if (tbLogin.Text.Trim().Length > 0)
                {
                    if (tbPassword.Text.Trim().Length > 0)
                    {
                        data += "DB:" + tbAddress.Text.Trim() + ";\nlogin:"******";\npassword:"******";";
                    }
                    else
                    {
                        MessageBoxEx.Show(this, "Введите пароль!", "Ошибка ввода");
                    }
                }
                else
                {
                    MessageBoxEx.Show(this, "Введите логин!", "Ошибка ввода");
                }
            }
            else
            {
                MessageBoxEx.Show(this, "Введите ссылку на базу даных!", "Ошибка ввода");
            }
            if (data.Length > 0)
            {
                File.WriteAllText(path, Cryptor.Encrypt(data, true));

                if (!DBManager.ReloadUsersAuthData())
                {
                    MessageBoxEx.Show(this, "Ошибка при сохранении даных - перезапустите программу.", "Ошибка программы");
                }
                Close();
            }
        }
Esempio n. 2
0
        private static bool ReadAuthData()
        {
            string serverName   = "";
            string userName     = "";
            string password     = "";
            string databaseName = "nekrasof_ticket";

            try
            {
                string text = Cryptor.Decrypt(File.ReadAllText(@"ClientsIdentification.stg"), true);

                int indexStart  = text.IndexOf(":");
                int indexFinish = text.IndexOf(";");

                serverName = text.Substring(indexStart + 1, indexFinish - indexStart - 1);
                text       = text.Remove(0, indexFinish + 1);

                indexStart  = text.IndexOf(":");
                indexFinish = text.IndexOf(";");

                userName = text.Substring(indexStart + 1, indexFinish - indexStart - 1);
                text     = text.Remove(0, indexFinish + 1);

                indexStart  = text.IndexOf(":");
                indexFinish = text.IndexOf(";");

                password = text.Substring(indexStart + 1, indexFinish - indexStart - 1);

                if (userName.Equals("") || password.Equals("") || serverName.Equals(""))
                {
                    LAST_ERROR = (int)ERRORS.SETTING;

                    return(false);
                }

                indexStart  = serverName.IndexOf("://");
                indexFinish = serverName.IndexOf("/", 9);

                if (indexStart >= 0 && indexFinish >= 0 && indexFinish != indexStart)
                {
                    serverName = serverName.Substring(indexStart + 3, indexFinish - indexStart - 3);
                }

                AUTH_DATA[0] = serverName;
                AUTH_DATA[1] = userName;

                MySqlConnectionStringBuilder mysqlCSB = new MySqlConnectionStringBuilder();
                mysqlCSB.Server             = serverName;
                mysqlCSB.Database           = databaseName;
                mysqlCSB.UserID             = userName;
                mysqlCSB.Password           = password;
                mysqlCSB.ConnectionProtocol = MySqlConnectionProtocol.UnixSocket;

                connectionString = mysqlCSB.ConnectionString;
            }
            catch (Exception e)
            {
                LAST_ERROR = (int)ERRORS.SETTING;

                return(false);
            }

            return(true);
        }