Example #1
0
        private bool LoginOnServer()
        {
            try
            {
                if (LoginServer.IsConnected)
                {
                    return(true);
                }

                if ((Identifier.Text.Replace(" ", "") != "" && Password.Text.Replace(" ", "") != ""))
                {
                    if (Remember.Checked)
                    {
                        Directory.CreateDirectory(Application.StartupPath + "\\Settings\\");
                        var sw = new StreamWriter(Application.StartupPath + "\\Settings\\.login");
                        sw.WriteLine(Others.EncryptString(Identifier.Text.Trim() + "#" + Password.Text.Trim()));
                        sw.Close();
                    }
                    else
                    {
                        string fileToDelete = Application.StartupPath + "\\Settings\\.login";
                        if (File.Exists(fileToDelete))
                        {
                            File.Delete(fileToDelete);
                        }
                    }

                    LoginServer.Connect(Identifier.Text.Trim(), Password.Text.Trim());

                    while (!LoginServer.IsConnected)
                    {
                        Application.DoEvents();
                        Thread.Sleep(100);
                    }

                    return(LoginServer.IsConnected);
                }
            }
            catch (Exception ex)
            {
                Logging.WriteError("LoginOnServer(): " + ex);
            }
            MessageBox.Show(nManager.Translate.Get(nManager.Translate.Id.Please_enter_your_user_name_and_password) + ".",
                            nManager.Translate.Get(nManager.Translate.Id.Error), MessageBoxButtons.OK, MessageBoxIcon.Error);
            return(false);
        }