Пример #1
0
        private void CreateFilePassword()
        {
            TechOperations.CheckIfSettingsExists();

            string readJson  = File.ReadAllText(TechOperations.CurrentWorkingFile);
            var    decrypted = SecureHelper.DecryptString(readJson);

            var desJson = JsonConvert.DeserializeObject <List <PasswordModel> >(decrypted);

            if (desJson == null)
            {
                desJson = new List <PasswordModel>();
            }

            var pass = new PasswordModel {
                Username = this.FileName, Password = this.FilePassword
            };

            desJson.Add(pass);

            var json = JsonConvert.SerializeObject(desJson);

            using (var writer = new StreamWriter(TechOperations.SettingsFileLocation, true))
            {
                var text = SecureHelper.EncryptString(json);
                writer.Write(text);
            }
        }
Пример #2
0
        private void SavePassword()
        {
            var pass = new PasswordModel
            {
                Name        = this.Name,
                Description = this.Description,
                Username    = this.Username,
                Password    = this.Password,
                Address     = this.Address
            };

            string readJson  = File.ReadAllText(TechOperations.CurrentWorkingFile);//(@"C:\Development\Playground\secure.kh");
            var    decrypted = SecureHelper.DecryptString(readJson);

            var cleaner = File.CreateText(TechOperations.CurrentWorkingFile);//(@"C:\Development\Playground\secure.kh");

            cleaner.Flush();
            cleaner.Close();

            var desJson = JsonConvert.DeserializeObject <List <PasswordModel> >(decrypted);

            if (desJson == null)
            {
                desJson = new List <PasswordModel>();
            }

            desJson.Add(pass);

            var json = JsonConvert.SerializeObject(desJson);

            using (var writer = new StreamWriter(TechOperations.CurrentWorkingFile, true))//(@"C:\Development\Playground\secure.kh", true))
            {
                var text = SecureHelper.EncryptString(json);
                writer.Write(text);
            }

            MessageBox.Show("Your password has been created!", "Info", MessageBoxButton.OK, MessageBoxImage.Information);

            this.Name        = string.Empty;
            this.Description = string.Empty;
            this.Username    = string.Empty;
            this.Password    = string.Empty;
            this.Address     = string.Empty;
        }