working password saving
This commit is contained in:
parent
a6ebcf2c6c
commit
305dcbd794
5 changed files with 80 additions and 4 deletions
|
@ -1,3 +1,4 @@
|
|||
using System;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls.ApplicationLifetimes;
|
||||
using Avalonia.Markup.Xaml;
|
||||
|
@ -15,7 +16,7 @@ public partial class App : Application
|
|||
{
|
||||
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
|
||||
{
|
||||
desktop.MainWindow = new MainWindow();
|
||||
desktop.MainWindow = new PasswordWindow();
|
||||
}
|
||||
|
||||
base.OnFrameworkInitializationCompleted();
|
||||
|
|
|
@ -11,6 +11,7 @@ namespace Cryptura;
|
|||
public partial class MainWindow : Window
|
||||
{
|
||||
public static bool censorPasswords = true;
|
||||
public static string MasterPassword = "";
|
||||
private void AdjustThemeToPlatform()
|
||||
{
|
||||
if (Core.IsRunningOnGnome())
|
||||
|
@ -26,10 +27,12 @@ public partial class MainWindow : Window
|
|||
AcrylicBorderObject.IsVisible = true;
|
||||
}
|
||||
}
|
||||
public MainWindow()
|
||||
public MainWindow(string masterPassword)
|
||||
{
|
||||
InitializeComponent();
|
||||
MasterPassword = masterPassword;
|
||||
AdjustThemeToPlatform();
|
||||
Password pw = new Password("Example", "Password");
|
||||
FetchPasswords();
|
||||
}
|
||||
|
||||
|
|
27
Cryptura/PasswordWindow.axaml
Normal file
27
Cryptura/PasswordWindow.axaml
Normal file
|
@ -0,0 +1,27 @@
|
|||
<Window xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="Cryptura.PasswordWindow"
|
||||
TransparencyLevelHint="AcrylicBlur"
|
||||
Background="Transparent"
|
||||
Title="Enter Master Password"
|
||||
Width="430"
|
||||
Height="170">
|
||||
<Panel>
|
||||
<ExperimentalAcrylicBorder IsHitTestVisible="False" Name="AcrylicBorderObject">
|
||||
<ExperimentalAcrylicBorder.Material>
|
||||
<ExperimentalAcrylicMaterial
|
||||
BackgroundSource="Digger"
|
||||
TintColor="Black"
|
||||
TintOpacity="1"
|
||||
MaterialOpacity="0.65"/>
|
||||
</ExperimentalAcrylicBorder.Material>
|
||||
</ExperimentalAcrylicBorder>
|
||||
<Grid RowDefinitions="*,*,*,*">
|
||||
<TextBox Grid.Row="1" Name="MasterPasswordBox" HorizontalAlignment="Center" VerticalAlignment="Center" Width="300" PasswordChar="*"/>
|
||||
<Button Grid.Row="2" Name="MasterPasswordConfirm" Content="Confirm" Click="MasterPasswordConfirm_OnClick" HorizontalAlignment="Center" VerticalAlignment="Center"/>
|
||||
</Grid>
|
||||
</Panel>
|
||||
</Window>
|
43
Cryptura/PasswordWindow.axaml.cs
Normal file
43
Cryptura/PasswordWindow.axaml.cs
Normal file
|
@ -0,0 +1,43 @@
|
|||
using System;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Interactivity;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using Avalonia.Media;
|
||||
|
||||
namespace Cryptura;
|
||||
|
||||
public partial class PasswordWindow : Window
|
||||
{
|
||||
private void AdjustThemeToPlatform()
|
||||
{
|
||||
if (Core.IsRunningOnGnome())
|
||||
{
|
||||
this.TransparencyLevelHint = new[] { WindowTransparencyLevel.None };
|
||||
this.Background = new SolidColorBrush(Color.Parse("#201c29"));
|
||||
AcrylicBorderObject.IsVisible = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.TransparencyLevelHint = new[] { WindowTransparencyLevel.AcrylicBlur };
|
||||
this.Background = Brushes.Transparent;
|
||||
AcrylicBorderObject.IsVisible = true;
|
||||
}
|
||||
}
|
||||
public PasswordWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
AdjustThemeToPlatform();
|
||||
}
|
||||
|
||||
private void WindowBase_OnResized(object? sender, WindowResizedEventArgs e)
|
||||
{
|
||||
Console.WriteLine(e.ClientSize);
|
||||
}
|
||||
|
||||
private void MasterPasswordConfirm_OnClick(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
new MainWindow(MasterPasswordBox.Text ?? "").Show();
|
||||
this.Close();
|
||||
}
|
||||
}
|
|
@ -79,7 +79,7 @@ namespace Cryptura
|
|||
try
|
||||
{
|
||||
var lines = File.ReadAllLines(this.Path);
|
||||
return lines.Length >= 3 ? lines[2] : "";
|
||||
return lines.Length >= 3 ? EncryptionLibrary.Decrypt(MainWindow.MasterPassword, lines[2]) : "";
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
@ -91,12 +91,14 @@ namespace Cryptura
|
|||
{
|
||||
try
|
||||
{
|
||||
string encryptedHash = EncryptionLibrary.Encrypt(MainWindow.MasterPassword, value);
|
||||
|
||||
var lines = File.ReadAllLines(this.Path);
|
||||
|
||||
if (lines.Length < 3)
|
||||
Array.Resize(ref lines, 3);
|
||||
|
||||
lines[2] = value;
|
||||
lines[2] = encryptedHash;
|
||||
File.WriteAllLines(this.Path, lines);
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
|
Loading…
Add table
Reference in a new issue