Skip to content

Commit 9d0065e

Browse files
committed
Finished encryption service
1 parent 6039300 commit 9d0065e

9 files changed

+36
-37
lines changed

MyCryptoMonitor/Forms/MainForm.Designer.cs

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

MyCryptoMonitor/Forms/MainForm.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ private void MainForm_Load(object sender, EventArgs e)
5656
UserConfigService.Load();
5757

5858
//Unlock if encryption is enabled
59-
EncryptionService.Unlock();
59+
if (UserConfigService.Encrypted)
60+
EncryptionService.Unlock();
6061

6162
//Attempt to load portfolio on startup
6263
_coinConfigs = PortfolioService.LoadStartup();

MyCryptoMonitor/Forms/ManageEncryption.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ private void btnEncrypt_Click(object sender, EventArgs e)
2323
if (string.IsNullOrEmpty(txtPassword.Text))
2424
return;
2525

26-
if (UserConfigService.Encrypted && EncryptionService.CheckPassword(txtPassword.Text))
26+
if (UserConfigService.Encrypted && EncryptionService.ValidatePassword(txtPassword.Text))
2727
{
2828
EncryptionService.DecryptFiles();
2929

MyCryptoMonitor/Forms/InputPassword.Designer.cs renamed to MyCryptoMonitor/Forms/Unlock.Designer.cs

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

MyCryptoMonitor/Forms/InputPassword.cs renamed to MyCryptoMonitor/Forms/Unlock.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
namespace MyCryptoMonitor.Forms
44
{
5-
public partial class InputPassword : Form
5+
public partial class Unlock : Form
66
{
77
public string PasswordInput { get { return txtPassword.Text; } }
88

9-
public InputPassword()
9+
public Unlock()
1010
{
1111
InitializeComponent();
1212
}

MyCryptoMonitor/MyCryptoMonitor.csproj

+5-5
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,11 @@
109109
<Compile Include="Forms\NewUI.Designer.cs">
110110
<DependentUpon>NewUI.cs</DependentUpon>
111111
</Compile>
112-
<Compile Include="Forms\InputPassword.cs">
112+
<Compile Include="Forms\Unlock.cs">
113113
<SubType>Form</SubType>
114114
</Compile>
115-
<Compile Include="Forms\InputPassword.Designer.cs">
116-
<DependentUpon>InputPassword.cs</DependentUpon>
115+
<Compile Include="Forms\Unlock.Designer.cs">
116+
<DependentUpon>Unlock.cs</DependentUpon>
117117
</Compile>
118118
<Compile Include="Forms\ManagePortfolios.cs">
119119
<SubType>Form</SubType>
@@ -150,8 +150,8 @@
150150
<EmbeddedResource Include="Forms\NewUI.resx">
151151
<DependentUpon>NewUI.cs</DependentUpon>
152152
</EmbeddedResource>
153-
<EmbeddedResource Include="Forms\InputPassword.resx">
154-
<DependentUpon>InputPassword.cs</DependentUpon>
153+
<EmbeddedResource Include="Forms\Unlock.resx">
154+
<DependentUpon>Unlock.cs</DependentUpon>
155155
</EmbeddedResource>
156156
<EmbeddedResource Include="Forms\ManagePortfolios.resx">
157157
<DependentUpon>ManagePortfolios.cs</DependentUpon>

MyCryptoMonitor/Statics/EncryptionService.cs

+20-22
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,24 @@ public static class EncryptionService
1717
#endregion
1818

1919
#region Methods
20-
public static bool CheckPassword(string password)
20+
public static bool ValidatePassword(string password)
2121
{
2222
return AesDecryptString(File.ReadAllText(CHECKFILE), password).Equals(CHECKVALUE);
2323
}
2424

2525
public static void Unlock()
2626
{
27-
if (!UserConfigService.Encrypted)
28-
return;
29-
30-
using (InputPassword form = new InputPassword())
27+
using (Unlock form = new Unlock())
3128
{
3229
var result = form.ShowDialog();
3330

3431
if (result == DialogResult.OK)
3532
{
36-
if (!CheckPassword(form.PasswordInput))
33+
if (!ValidatePassword(form.PasswordInput))
34+
{
3735
Unlock();
36+
return;
37+
}
3838

3939
_password = form.PasswordInput;
4040
}
@@ -55,45 +55,43 @@ public static void Unlock()
5555
public static void EncryptFiles(string password)
5656
{
5757
_password = password;
58-
UserConfigService.Encrypted = true;
59-
60-
File.WriteAllText(CHECKFILE, AesEncryptString(CHECKVALUE));
6158

59+
CreateCheckFile();
60+
UserConfigService.Encrypted = true;
6261
UserConfigService.Save();
6362
PortfolioService.EncryptPortfolios();
6463
AlertService.EncryptAlerts();
6564
}
6665

6766
public static void DecryptFiles()
6867
{
69-
UserConfigService.Encrypted = false;
70-
7168
DeleteCheckFile();
72-
69+
UserConfigService.Encrypted = false;
7370
UserConfigService.Save();
7471
PortfolioService.DecryptPortfolios();
7572
AlertService.DecryptAlerts();
7673
}
7774

78-
public static void DeleteCheckFile()
79-
{
80-
81-
if (File.Exists(CHECKFILE))
82-
File.Delete(CHECKFILE);
83-
}
84-
8575
public static void Reset()
8676
{
8777
DeleteCheckFile();
88-
8978
PortfolioService.DeleteAll();
9079
AlertService.Delete();
9180
UserConfigService.Delete();
9281
}
93-
#endregion
94-
9582

83+
private static void CreateCheckFile()
84+
{
85+
if (!File.Exists(CHECKFILE))
86+
File.WriteAllText(CHECKFILE, AesEncryptString(CHECKVALUE));
87+
}
9688

89+
private static void DeleteCheckFile()
90+
{
91+
if (File.Exists(CHECKFILE))
92+
File.Delete(CHECKFILE);
93+
}
94+
#endregion
9795

9896
#region Encrypt
9997
public static string AesEncryptString(string clearText)

MyCryptoMonitor/Statics/PortfolioService.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public static void Delete(string portfolio)
6666
public static void DeleteAll()
6767
{
6868
foreach(var portfolio in GetPortfolios())
69-
File.Delete(portfolio + FILEEXTENSION);
69+
File.Delete(portfolio.FileName);
7070
}
7171
#endregion
7272

0 commit comments

Comments
 (0)