Beispiel #1
0
 public static MemoryStream getSerializedStream(ProfileType profile)
 {
     BinaryFormatter binFormatter = new BinaryFormatter();
     MemoryStream mStream = new MemoryStream();
     binFormatter.Serialize(mStream, profile);
     return mStream;
 }
Beispiel #2
0
        public static void HandelProfileCreation(CreateProfileView sender)
        {
            sender.TextBlockErrorDisplay.Text = "";
            bool NoFailture = true;

            if (DataOperations.ChekProfileFileExsists(sender.TextBoxUserInputProfileName.Text))
            {
                sender.TextBlockErrorDisplay.Text += "Profile already exist!\n";
                NoFailture = false;
            }

            if (sender.TextBoxUserInputProfileName.Text.Count() <= 0)
            {
                sender.TextBlockErrorDisplay.Text += "Your Profilename have to be longer than 0 Charakters!\n";
                NoFailture = false;
            }

            if (!DataOperations.ComparePasswords(sender.PasswordBoxUserInputPassword.Password, sender.PasswordBoxUserInputPasswordRepate.Password))
            {
                sender.TextBlockErrorDisplay.Text += "The Passwords are not the same!\n";
                NoFailture = false;
            }

            if (NoFailture)
            {
                ProfileType Profile = new ProfileType();
                Profile.ProfileName = sender.TextBoxUserInputProfileName.Text;
                DataOperations.WriteProfileToDisk(Profile, sender.PasswordBoxUserInputPassword.Password);
                AppData.PointerMainWindow.Content = new StartupView();
            }
        }
Beispiel #3
0
 public static ProfileType getDeserializedProfile(MemoryStream mStream)
 {
     BinaryFormatter binFormatter = new BinaryFormatter();
     ProfileType profile = new ProfileType();
     if (mStream.Length == 1)
     {
         profile = new ProfileType();
     }
     else
     {
         profile = (ProfileType)binFormatter.Deserialize(mStream);
     }
     return profile;
 }
Beispiel #4
0
        public static ProfileType getDeserializedProfile(MemoryStream mStream)
        {
            BinaryFormatter binFormatter = new BinaryFormatter();
            ProfileType     profile      = new ProfileType();

            if (mStream.Length == 1)
            {
                profile = new ProfileType();
            }
            else
            {
                profile = (ProfileType)binFormatter.Deserialize(mStream);
            }
            return(profile);
        }
Beispiel #5
0
 public static ProfileType GetProfileFromDisk(string ProfileName, string Key)
 {
     if(ChekProfileFileExsists(ProfileName))
     {
         FileStream FileStream;
         MemoryStream MemoryStream;
         try
         {
             FileStream = new FileStream(DataOperations.GetProfileFilePath(ProfileName), FileMode.Open);
             byte[] EncrypedFromStream = new byte[FileStream.Length];
             FileStream.Read(EncrypedFromStream, 0, EncrypedFromStream.Length);
             MemoryStream = new MemoryStream(CryptographyHelper.Decrypt(EncrypedFromStream, Key));
         }
         catch
         {
             ProfileType Profile = new ProfileType();
             Profile.ErrorCode = (short)Enumerators.ProfileTypeErrorCodes.ReadFileError;
             return Profile;
         }
         try
         {
             ProfileType Profile = Serializer.getDeserializedProfile(MemoryStream);
             FileStream.Close();
             MemoryStream.Close();
             Profile.ErrorCode = (short)Enumerators.ProfileTypeErrorCodes.NoFailture;
             return Profile;
         }
         catch
         {
             ProfileType Profile = new ProfileType();
             Profile.ErrorCode = (short)Enumerators.ProfileTypeErrorCodes.SerializerError;
             return Profile;
         }
     }
     else
     {
         ProfileType Profile = new ProfileType();
         Profile.ErrorCode = (short)Enumerators.ProfileTypeErrorCodes.FileNotFound;
         return Profile;
     }
 }
Beispiel #6
0
 public static ProfileType GetProfileFromDisk(string ProfileName, string Key)
 {
     if (ChekProfileFileExsists(ProfileName))
     {
         FileStream   FileStream;
         MemoryStream MemoryStream;
         try
         {
             FileStream = new FileStream(DataOperations.GetProfileFilePath(ProfileName), FileMode.Open);
             byte[] EncrypedFromStream = new byte[FileStream.Length];
             FileStream.Read(EncrypedFromStream, 0, EncrypedFromStream.Length);
             MemoryStream = new MemoryStream(CryptographyHelper.Decrypt(EncrypedFromStream, Key));
         }
         catch
         {
             ProfileType Profile = new ProfileType();
             Profile.ErrorCode = (short)Enumerators.ProfileTypeErrorCodes.ReadFileError;
             return(Profile);
         }
         try
         {
             ProfileType Profile = Serializer.getDeserializedProfile(MemoryStream);
             FileStream.Close();
             MemoryStream.Close();
             Profile.ErrorCode = (short)Enumerators.ProfileTypeErrorCodes.NoFailture;
             return(Profile);
         }
         catch
         {
             ProfileType Profile = new ProfileType();
             Profile.ErrorCode = (short)Enumerators.ProfileTypeErrorCodes.SerializerError;
             return(Profile);
         }
     }
     else
     {
         ProfileType Profile = new ProfileType();
         Profile.ErrorCode = (short)Enumerators.ProfileTypeErrorCodes.FileNotFound;
         return(Profile);
     }
 }
Beispiel #7
0
 private void MenuItemLogin_Click(object sender, RoutedEventArgs e)
 {
     ProfileType Profile = new ProfileType();
     Profile = DataSafeBackend.DataOperations.GetProfileFromDisk(ProfileName,passwordBox1.Password);
     if (Profile.ErrorCode == (short)Enumerators.ProfileTypeErrorCodes.NoFailture)
     {
         AppData.ActiveProfile = Profile;
         AppData.PointerMainWindow.Content = new ProfileContentView();
     }
     else
     {
         this.TextBlockErrorDisplay.Text = "";
         switch (Profile.ErrorCode)
         {
             case (short)Enumerators.ProfileTypeErrorCodes.FileNotFound: this.TextBlockErrorDisplay.Text = "File not Found!";
                 break;
             case (short)Enumerators.ProfileTypeErrorCodes.ReadFileError: this.TextBlockErrorDisplay.Text = "Could not read the Profilefile!";
                 break;
             case (short)Enumerators.ProfileTypeErrorCodes.SerializerError: this.TextBlockErrorDisplay.Text = "The Password might be wrong!";
                 break;
         }
     }
 }
Beispiel #8
0
 public static void WriteProfileToDisk(ProfileType profile, string key)
 {
     FileStream fStream = File.Open(Path.Combine(DataOperations.GetProfilePath(), profile.ProfileName + ".dat"), FileMode.Create);
     byte[] encryptedBytes = CryptographyHelper.Encrypt(Serializer.getSerializedStream(profile).ToArray(), key);
     fStream.Write(encryptedBytes, 0, encryptedBytes.Length);
     fStream.Close();
 }