Example #1
0
 private static void CancelAuthorization(object sender, EventArgs e)
 {
     preLogin.NewDataInputed -= new EventHandler<EventArgs>(TestAccount);
     preLogin.Canceled -= new EventHandler<EventArgs>(CancelAuthorization);
     textError = "Отмена авторизации";
     attemptCounter = 0;
     state = MySecurityState.userCancelAuthorisation;
 }
Example #2
0
 static MySecurity()
 {
     attemptCounter = 0;
     state = MySecurityState.empty;
 }
Example #3
0
        private static void TestAccount(object send, EventArgs e)
        {
            _userName = preLogin.GetUserName();
            _password = preLogin.GetPassword();
            _serverName = preLogin.GetServerName();
            _dbName = preLogin.GetDbName();
            _dbFileName = preLogin.GetDbFileName();
            _locationServerDb = preLogin.GetLocationServerDb();
            _isWindowsAuthentication = preLogin.isWindowsAuthentication();
            string stringTest;
            if (_locationServerDb)
            {
                stringTest = String.Format(
                     @"data source={0}; Initial Catalog={1}; integrated security={2}; connect timeout=30; multipleactiveresultsets=True; User ID = {3}; Password = {4}; App=EntityFramework"
                     , _serverName
                     , _dbName
                     , _isWindowsAuthentication
                     , _userName
                     , _password);
            }
            else
            {
                stringTest = String.Format(
                    @"data source={0};attachdbfilename={1};User Instance={2};integrated security={2};connect timeout=30; User ID = {3}; Password = {4};multipleactiveresultsets=True;App=EntityFramework"
                     , _serverName
                     , _dbFileName
                     , _isWindowsAuthentication
                     , _userName
                     , _password);
            }

            try
            {
                SqlConnection conntest = new SqlConnection(stringTest);
                conntest.Open();
                conntest.Close();
            }
            catch (SqlException ex)
            {
                Exception = ex;
                if (ex.Number == 5120)
                {
                    textError = "В случае SQL авторизации, для учётной записи под которой работает SQL2008 EXPRESS должны быть предоставлены полные права для файлов данных MDF и LDF";
                }
                else
                {
                    textError = "Не удачная попытка соединения с БД";
                }
                state = MySecurityState.dbAccessFailure;
                string message = textError + Environment.NewLine + ex.Message;
                PException pexception = StaticInformation.ninjectKernel.Get<PException>(new ConstructorArgument("MessageText", message, false));
                pexception.Show();

                _connectionString = string.Empty;
                NewAuthorizationAttempt();
                return;
            }
            state = MySecurityState.success;
            var entityConnectionString = new EntityConnectionStringBuilder()
            {
                Metadata = @"res://*/Model.Model1.csdl|res://*/Model.Model1.ssdl|res://*/Model.Model1.msl",
                Provider = @"System.Data.SqlClient",
                ProviderConnectionString = stringTest
            };
            _connectionString = entityConnectionString.ConnectionString;
            SetCurrentPrincipal(stringTest);
        }