private void BtnOk_Click(object sender, RoutedEventArgs e)
 {
     HashedPassword = Hasher.Hash(PwdBox.SecurePassword);
     PwdBox.Clear();
 }
Exemplo n.º 2
0
        private void ApplyLogin(object parameter)
        {
            try
            {
                if (string.IsNullOrEmpty(UserId.Trim()))
                {
                    throw new Exception("Логин не задан");
                }

                var passwordContainer = parameter as IPasswordContainer;

                if (passwordContainer == null || string.Equals(passwordContainer.HashedPassword, Hasher.Hash(null)))
                {
                    throw new Exception("Пароль не задан");
                }

                using (var loginService = _ppsClientViewModel.ServiceProxy.GetPpsChannelFactory <ILoginService>())
                {
                    var channel  = loginService.CreateChannel();
                    var selected = channel.GetLogin(new LoginDataContract {
                        Login = UserId
                    });

                    if (!selected.BoolRes)
                    {
                        throw new Exception(selected.ErrorRes);
                    }

                    if (selected.SomeResult == null || !selected.SomeResult.Any())
                    {
                        throw new Exception("Логин не найден");
                    }

                    var user = selected.SomeResult.FirstOrDefault();

                    if (!string.Equals(passwordContainer.HashedPassword, user.Password))
                    {
                        throw new Exception("Не верный пароль");
                    }

                    if (!user.GroupName.ToLower().Contains("администратор"))
                    {
                        throw new Exception("Пользователь не администратор");
                    }

                    if (string.IsNullOrEmpty(user.Certificate))
                    {
                        throw new Exception("Пустой сертификат");
                    }

                    SerializeCertificate(user.Certificate);
                    string deviceSerial;
                    var    deviceId = GetCurrentMachineId(out deviceSerial);
                    RaiseOnLoginApplied(user.LoginId, deviceId, deviceSerial, user.Login, user.UserName);
                    _ppsClientViewModel.AddEvent(EventConstants.EVENT_LOGON, user.UserName);
                    LoginNotApplied = false;
                }
            }
            catch (Exception ex)
            {
                StatusMessage = ex.Message;
                _ppsClientViewModel.AddEvent(EventConstants.EVENT_ERROR, string.Concat("Ошибка входа. ", ex.Message));
            }
        }