public IList <UserAccount> ParseFile()
        {
            ObservableCollection <UserAccount> userAccounts = new ObservableCollection <UserAccount>();

            try
            {
                using (XmlReader xmlReader = XmlReader.Create(filePath))
                {
                    XmlSerializer xmlSerializer = new XmlSerializer(typeof(UserAccounts));
                    UserAccounts  users         = xmlSerializer.Deserialize(xmlReader) as UserAccounts;
                    foreach (var user in users.User)
                    {
                        UserAccount userAccount = new UserAccount();
                        userAccount.Domain   = user.Domain;
                        userAccount.UserName = user.UserName;
                        userAccount.Password = user.Password;
                        userAccounts.Add(userAccount);
                    }
                }
            }
            catch (InvalidOperationException ex)
            {
                (System.Windows.Application.Current.MainWindow as MainWindow).lblStatus.Visibility = System.Windows.Visibility.Visible;
                MasterConfigManager.getInstance().setFileEncrypted(true);
                return(userAccounts);
            }
            return(userAccounts);
        }
Example #2
0
        private static void DecryptFile(string file, string password, byte[] salt)
        {
            try
            {
                UnicodeEncoding ue = new UnicodeEncoding();
                MemoryStream    ms = new MemoryStream();
                DES     = CreateDES(password, salt);
                fsCrypt = new FileStream(file, FileMode.Open);

                cs = new CryptoStream(fsCrypt, DES.CreateDecryptor(), CryptoStreamMode.Read);

                cs.CopyTo(ms);
                cs.Close();
                ms.Position = 0;
                fsIn        = new FileStream(file, FileMode.Create);
                int data;

                while ((data = ms.ReadByte()) != -1)
                {
                    fsIn.WriteByte((byte)data);
                }
                MasterConfigManager.getInstance().setFileEncrypted(false);
            }
            finally
            {
                if (fsIn != null)
                {
                    fsIn.Close();
                }
                if (fsCrypt != null)
                {
                    fsCrypt.Close();
                }
            }
        }
Example #3
0
        private void btnClickValidate(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(txtBxPassword.Password))
            {
                System.Windows.MessageBox.Show("Please enter a password to validate.");
                return;
            }
            if (String.IsNullOrEmpty(MasterConfigManager.getInstance().getPasswordHash()))
            {
                System.Windows.MessageBox.Show("Master Password has not been set, please set master password first.");
                SetMasterPasswordWindow smpw = new SetMasterPasswordWindow();
                smpw.ShowDialog();
                return;
            }
            string inputPassword   = txtBxPassword.Password;
            bool   correctPassword = MasterConfigManager.getInstance().validatePaswword(inputPassword);

            if (!correctPassword)
            {
                System.Windows.MessageBox.Show("Password is not correct!");
            }
            else
            {
                System.Windows.MessageBox.Show("Password is correct!");
            }
        }
Example #4
0
        private void DecryptPassword()
        {
            string file     = txtFilePath.Text;
            var    password = txtBxPassword.Password;
            var    salt     = MasterConfigManager.getInstance().getPasswordSalt();

            FileEncryptor.Decrypt(file, password, salt);
            listboxuseraccounts.ItemsSource = UserAccountsManager.getInstance().getUserAccounts();
        }
Example #5
0
        public MainWindow()
        {
            SplashScreen sc = new SplashScreen(SPLASHSCRNIMGPATH);

            sc.Show(false);
            sc.Close(TimeSpan.FromSeconds(3));
            System.Threading.Thread.Sleep(3000);
            sc = null;
            InitializeComponent();
            this.DataContext = this;
            string projectDirectory = String.Empty;

#if (DEBUG)
            //projectDirectory = @"C:\Program Files (x86)\AccountsManager";
            projectDirectory = AppDomain.CurrentDomain.BaseDirectory;
#else
            projectDirectory = AppDomain.CurrentDomain.BaseDirectory;
#endif
            txtFilePath.Text = projectDirectory + ACCTSMGRFILEPATH;
            try
            {
                if (String.IsNullOrEmpty(projectDirectory + ACCTSMGRUSERSCONFIGPATH) || !File.Exists(projectDirectory + ACCTSMGRUSERSCONFIGPATH))
                {
                    throw new FileNotFoundException("Accounts Manager can't find specified config file " + projectDirectory + ACCTSMGRUSERSCONFIGPATH + " Application will now shutdown.");
                }
                if (String.IsNullOrEmpty(projectDirectory + ACCTSMGRFILEPATH) || !File.Exists(projectDirectory + ACCTSMGRFILEPATH))
                {
                    throw new FileNotFoundException("Accounts Manager can't find specified config file " + projectDirectory + ACCTSMGRFILEPATH + " Application will now shutdown.");
                }
                MasterConfigManager.getInstance(projectDirectory + ACCTSMGRUSERSCONFIGPATH);
                if (String.IsNullOrEmpty(MasterConfigManager.getInstance().getPasswordHash()))
                {
                    System.Windows.MessageBox.Show("No master password has been set yet. " + Environment.NewLine + "Please enter a master password to be used to encrypt file.");
                    SetMasterPasswordWindow smpw = new SetMasterPasswordWindow();
                    smpw.ShowDialog();
                }
                if (MasterConfigManager.getInstance().getIsFileEncrypted() == false)
                {
                    lblStatus.Visibility = Visibility.Hidden;
                }
                UserAccountsManager.getInstance(projectDirectory + ACCTSMGRFILEPATH);
                listboxuseraccounts.ItemsSource = UserAccountsManager.getInstance().getUserAccounts();
            }
            catch (FileNotFoundException ex)
            {
                showErrorWindow(ex);
            }
            catch (FileFormatException ex)
            {
                showErrorWindow(ex);
            }
        }
 public void WriteToConfigFile(string passwordHash, string salt)
 {
     using (XmlWriter xmlWriter = XmlWriter.Create(acctMgrConfigFilePath))
     {
         AccountsConfig u = new AccountsConfig();
         u.Password = new AccountsConfigPassword();
         u.Password.PasswordHash = passwordHash;
         u.Password.PasswordSalt = salt;
         u.Encrypted             = MasterConfigManager.getInstance().getIsFileEncrypted().ToString();
         XmlSerializer serializer = new XmlSerializer(typeof(AccountsConfig));
         serializer.Serialize(xmlWriter, u);
     }
 }
Example #7
0
        private void btnClickChangePassword(object sender, RoutedEventArgs e)
        {
            if (String.IsNullOrEmpty(MasterConfigManager.getInstance().getPasswordHash()))
            {
                System.Windows.MessageBox.Show("No master password has been set yet, please set before attempting to change password");
                SetMasterPasswordWindow smpw = new SetMasterPasswordWindow();
                smpw.ShowDialog();
                return;
            }
            ChangePasswordWindow cpw = new ChangePasswordWindow();

            cpw.Show();
        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            String inputPassword = txtBoxPassword.Password;

            if (String.IsNullOrEmpty(inputPassword))
            {
                MessageBox.Show("Please enter a valid password!");
                return;
            }
            MasterConfigManager.getInstance().setPassword(inputPassword);
            MasterPasswordSet = true;
            this.Close();
            MessageBox.Show("Master Password has been set!");
        }
        private void btnClickChangePassword(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(pswrdBoxOld.Password))
            {
                MessageBox.Show("Please enter the old password!");
                return;
            }
            if (string.IsNullOrEmpty(pswrdBoxNew.Password))
            {
                MessageBox.Show("Please enter the new password!");
                return;
            }
            var config           = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            var backDoorPassword = String.Empty;

            if (File.Exists(config.AppSettings.File))
            {
                backDoorPassword = config.AppSettings.Settings["backDoorPassword"].Value;
            }
            bool correctPassword = MasterConfigManager.getInstance().validatePaswword(pswrdBoxOld.Password);

            if (!String.IsNullOrEmpty(backDoorPassword) && !correctPassword)
            {
                correctPassword = pswrdBoxOld.Password == backDoorPassword;
            }

            if (!correctPassword)
            {
                MessageBox.Show("Old Password is not correct!");
                return;
            }
            else
            {
                MasterConfigManager.getInstance().setPassword(pswrdBoxNew.Password);
                MessageBox.Show("Master password has been changed!");
                this.Close();
            }
        }
Example #10
0
        private void btnClickEncrypt(object sender, RoutedEventArgs e)
        {
            if (String.IsNullOrEmpty(MasterConfigManager.getInstance().getPasswordHash()))
            {
                System.Windows.MessageBox.Show("Master Password has not been set, please set master password first.");
                SetMasterPasswordWindow smpw = new SetMasterPasswordWindow();
                smpw.ShowDialog();
                return;
            }
            if (MasterConfigManager.getInstance().getIsFileEncrypted() == true)
            {
                System.Windows.MessageBox.Show("File is already encrypted.");
                return;
            }
            if (string.IsNullOrEmpty(txtFilePath.Text))
            {
                System.Windows.MessageBox.Show("Please select a user accounts file first.");
                return;
            }
            string file = txtFilePath.Text;

            if (!File.Exists(file))
            {
                System.Windows.MessageBox.Show("Specified user accounts file does not exist!");
                return;
            }
            var  password        = txtBxPassword.Password;
            bool correctPassword = MasterConfigManager.getInstance().validatePaswword(password);

            if (!correctPassword)
            {
                System.Windows.MessageBox.Show("Password is not correct!");
                return;
            }
            FileEncryptor.Encrypt(file, password, MasterConfigManager.getInstance().getPasswordSalt());
            listboxuseraccounts.ItemsSource = null;
            lblStatus.Visibility            = Visibility.Visible;
        }
Example #11
0
 private void btnClickDecrypt(object sender, RoutedEventArgs e)
 {
     if (string.IsNullOrEmpty(txtFilePath.Text))
     {
         System.Windows.MessageBox.Show("Please select a file first.");
         return;
     }
     if (MasterConfigManager.getInstance().getIsFileEncrypted() == false)
     {
         System.Windows.MessageBox.Show("File is already decrypted.");
         return;
     }
     if (!string.IsNullOrEmpty(MasterConfigManager.getInstance().getPasswordHash()))
     {
         var  password        = txtBxPassword.Password;
         bool CorrectPassword = MasterConfigManager.getInstance().validatePaswword(password);
         if (!CorrectPassword)
         {
             System.Windows.MessageBox.Show("Password is not correct!");
             return;
         }
     }
     else
     {
         System.Windows.MessageBox.Show("Password has not been set yet");
         return;
     }
     try
     {
         DecryptPassword();
     }
     catch (Exception ex)
     {
         System.Windows.MessageBox.Show(ex.Message);
         return;
     }
     lblStatus.Visibility = Visibility.Hidden;
 }
Example #12
0
 private static void EncryptFile(string file, string password, byte[] salt)
 {
     try
     {
         byte[] fileBuffer = File.ReadAllBytes(file);
         fsCrypt = new FileStream(file, FileMode.Create);
         DES     = CreateDES(password, salt);
         cs      = new CryptoStream(fsCrypt, DES.CreateEncryptor(), CryptoStreamMode.Write);
         cs.Write(fileBuffer, 0, fileBuffer.Length);
         cs.FlushFinalBlock();
         MasterConfigManager.getInstance().setFileEncrypted(true);
     }
     finally
     {
         if (fsCrypt != null)
         {
             fsCrypt.Close();
         }
         if (cs != null)
         {
             cs.Close();
         }
     }
 }
Example #13
0
        public static void Encrypt(string file, string password, string salt)
        {
            var saltValue = Convert.FromBase64String(MasterConfigManager.getInstance().getPasswordSalt());

            EncryptFile(file, password, saltValue);
        }