Skip to content

Commit

Permalink
Password protection and other fixes
Browse files Browse the repository at this point in the history
* Password protect info.dat file and require valid password on application start and when disabling protection.
* Fix properly minimizing to system tray.
* Fix steamguard window detection in different languages that utilize the em dash instead of regular hyphen.
* Lowercase ini variables.
* Rename settings window.
  • Loading branch information
rex706 committed Apr 16, 2019
1 parent e3e3a6b commit 6fb40a6
Show file tree
Hide file tree
Showing 8 changed files with 407 additions and 91 deletions.
4 changes: 2 additions & 2 deletions SAM/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:tb="http://www.hardcodet.net/taskbar"
xmlns:local="clr-namespace:SAM"
mc:Ignorable="d" Height="190" Width="138" WindowStartupLocation="CenterScreen" Icon="steam_alt-10.ico" ResizeMode="CanMinimize" Title="SAM" Background="#FF333638">
mc:Ignorable="d" Height="190" Width="138" WindowStartupLocation="CenterScreen" Icon="steam_alt-10.ico" ResizeMode="CanMinimize" Title="SAM" Background="#FF333638" StateChanged="Window_StateChanged">
<Window.Resources>
<!-- This style is used for buttons, to remove the WPF default 'animated' mouse over effect -->
<Style x:Key="SAMButtonStyle" TargetType="Button">
Expand Down Expand Up @@ -134,7 +134,7 @@

</MenuItem>
<Separator />
<MenuItem Header="Show" Click="ShowWindowButton_Click" />
<MenuItem Header="Restore" Click="ShowWindowButton_Click" />
<MenuItem Header="Exit" Click="ExitMenuItem_Click" />
</ContextMenu>
</tb:TaskbarIcon.ContextMenu>
Expand Down
230 changes: 164 additions & 66 deletions SAM/MainWindow.xaml.cs

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions SAM/PasswordWindow.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Window x:Name="PasswordWindowDialog" x:Class="SAM.PasswordWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
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"
xmlns:local="clr-namespace:SAM"
mc:Ignorable="d"
Title="Password" Height="130" Width="235" Background="#FF333638" ResizeMode="NoResize" WindowStartupLocation="CenterScreen" Topmost="True">
<Grid>
<Button Content="Ok" HorizontalAlignment="Left" Margin="73,63,0,0" VerticalAlignment="Top" Width="75" Click="Button_Click"/>
<PasswordBox x:Name="PasswordTextBox" PasswordChar="" HorizontalAlignment="Left" Height="23" Margin="10,32,0,0" VerticalAlignment="Top" Width="199" PreviewKeyDown="PasswordTextBox_PreviewKeyDown"/>
<Label Content="Password" HorizontalAlignment="Left" Margin="81,4,0,0" VerticalAlignment="Top" Foreground="White"/>

</Grid>
</Window>
66 changes: 66 additions & 0 deletions SAM/PasswordWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
using System.Windows;
using System.Windows.Input;

namespace SAM
{
/// <summary>
/// Interaction logic for Window2.xaml
/// </summary>
public partial class PasswordWindow : Window
{
public string PasswordText
{
get { return PasswordTextBox.Password; }
set { PasswordTextBox.Password = value; }
}

public PasswordWindow()
{
InitializeComponent();
PasswordTextBox.Focus();
}

private void PasswordTextBox_PreviewKeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Return)
{
if (validateInput())
{
DialogResult = true;
}
}
}

private void Button_Click(object sender, RoutedEventArgs e)
{
if (validateInput())
{
DialogResult = true;
}
}

private bool validateInput()
{
if (PasswordTextBox.Password.Length > 0)
{
PasswordText = PasswordTextBox.Password;
return true;
}
else if (PasswordTextBox.Password.Length == 0)
{
//MessageBoxResult messageBoxResult = MessageBox.Show("No password detected, are you sure?", "Confirm", MessageBoxButton.YesNo, MessageBoxImage.Warning);

//if (messageBoxResult == MessageBoxResult.OK)
//{
// return true;
//}

PasswordText = "";

return true;
}

return false;
}
}
}
7 changes: 7 additions & 0 deletions SAM/SAM.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@
</Compile>
<Compile Include="UpdateCheck.cs" />
<Compile Include="Utils.cs" />
<Compile Include="PasswordWindow.xaml.cs">
<DependentUpon>PasswordWindow.xaml</DependentUpon>
</Compile>
<Page Include="MainWindow.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
Expand All @@ -125,6 +128,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="PasswordWindow.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs">
Expand Down
12 changes: 7 additions & 5 deletions SAM/SettingsWindow.xaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Window x:Class="SAM.Window1"
<Window x:Class="SAM.SettingsWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
Expand All @@ -12,10 +12,12 @@
<TabControl HorizontalAlignment="Left" Height="142" VerticalAlignment="Top" Width="288" Margin="10,10,0,0" Background="{x:Null}">
<TabItem Header="General">
<Grid>
<Label x:Name="NumPerRowLabel" Content="Accounts/Row" HorizontalAlignment="Left" Margin="116,18,0,0" VerticalAlignment="Top" Foreground="#FFD1D1D1"/>
<TextBox x:Name="textBox" HorizontalAlignment="Left" Height="19" Margin="83,21,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="30" MaxLines="1" MaxLength="2" TextAlignment="Center" ToolTip="Adjust the number of accounts displayed per row" BorderBrush="#FF707070"/>
<CheckBox x:Name="startupCheckBox" Content="Start with Windows" HorizontalAlignment="Left" Margin="83,48,0,0" VerticalAlignment="Top" Foreground="#FFD1D1D1"/>
<CheckBox x:Name="startupMinCheckBox" Content="Start Minimized" HorizontalAlignment="Left" Margin="83,68,0,0" VerticalAlignment="Top" Foreground="#FFD1D1D1"/>
<Label x:Name="NumPerRowLabel" Content="Accounts/Row" HorizontalAlignment="Left" Margin="116,4,0,0" VerticalAlignment="Top" Foreground="#FFD1D1D1"/>
<TextBox x:Name="textBox" HorizontalAlignment="Left" Height="19" Margin="83,7,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="30" MaxLines="1" MaxLength="2" TextAlignment="Center" ToolTip="Adjust the number of accounts displayed per row" BorderBrush="#FF707070"/>
<CheckBox x:Name="startupCheckBox" Content="Start with Windows" HorizontalAlignment="Left" Margin="83,34,0,0" VerticalAlignment="Top" Foreground="#FFD1D1D1"/>
<CheckBox x:Name="startupMinCheckBox" Content="Start Minimized" HorizontalAlignment="Left" Margin="83,54,0,0" VerticalAlignment="Top" Foreground="#FFD1D1D1"/>
<CheckBox x:Name="minimizeToTrayCheckBox" Content="Minimize To Tray" HorizontalAlignment="Left" Margin="83,74,0,0" VerticalAlignment="Top" Foreground="#FFD1D1D1"/>
<CheckBox x:Name="passwordProtectCheckBox" Content="Password Protect" HorizontalAlignment="Left" Margin="83,94,0,0" VerticalAlignment="Top" Foreground="#FFD1D1D1" Checked="PasswordProtectCheckBox_Checked" Unchecked="PasswordProtectCheckBox_Unchecked"/>
</Grid>
</TabItem>
<TabItem Header="Auto-Login">
Expand Down
131 changes: 116 additions & 15 deletions SAM/SettingsWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@
using System.Reflection;
using System.Text.RegularExpressions;
using System.Windows;
using System.Windows.Controls;

namespace SAM
{
/// <summary>
/// Interaction logic for settings window.
/// </summary>
public partial class Window1 : Window
public partial class SettingsWindow : Window
{
public int AutoAccIdx { get; set; }

Expand All @@ -29,20 +28,27 @@ public string ResponseText
set { textBox.Text = value; }
}

public string Password { get; set; }

public bool Decrypt { get; set; }

private IniFile settingsFile;

private string start;
private string minimized;
private string minimizeToTray;
private string passwordProtect;
private string recent;
private string recentAcc;
private string selected;
private string selectedAcc;

public Window1()
public SettingsWindow()
{
InitializeComponent();

this.Loaded += new RoutedEventHandler(SettingsWindow_Loaded);
this.Decrypt = false;
}

private void SettingsWindow_Loaded(object sender, RoutedEventArgs e)
Expand All @@ -53,23 +59,39 @@ private void SettingsWindow_Loaded(object sender, RoutedEventArgs e)
textBox.Text = settingsFile.Read("AccountsPerRow", "Settings");
start = settingsFile.Read("StartWithWindows", "Settings");
minimized = settingsFile.Read("StartMinimized", "Settings");
minimizeToTray = settingsFile.Read("MinimizeToTray", "Settings");
passwordProtect = settingsFile.Read("PasswordProtect", "Settings");
recent = settingsFile.Read("Recent", "AutoLog");
recentAcc = settingsFile.Read("RecentAcc", "AutoLog");
selected = settingsFile.Read("Selected", "AutoLog");
selectedAcc = settingsFile.Read("SelectedAcc", "AutoLog");

if (start == "True")
if (start.ToLower().Equals("true"))
{
startupCheckBox.IsChecked = true;
}

if (minimized == "True")
if (minimized.ToLower().Equals("true"))
{
startupMinCheckBox.IsChecked = true;
}

if (recent == "True")
if (minimizeToTray.ToLower().Equals("true"))
{
minimizeToTrayCheckBox.IsChecked = true;
}

if (passwordProtect.ToLower().Equals("true"))
{
passwordProtectCheckBox.IsChecked = true;
}

if (recent.ToLower().Equals("true"))
{
mostRecentCheckBox.IsChecked = true;
recentAccountLabel.Text = MainWindow.encryptedAccounts[Int32.Parse(recentAcc)].Name;
}
else if (selected == "True")
else if (selected.ToLower().Equals("true"))
{
selectedAccountCheckBox.IsChecked = true;
selectedAccountLabel.Text = MainWindow.encryptedAccounts[Int32.Parse(selectedAcc)].Name;
Expand All @@ -82,11 +104,75 @@ private void SettingsWindow_Loaded(object sender, RoutedEventArgs e)
private void SaveSettings(string apr)
{
var settingsFile = new IniFile("SAMSettings.ini");

if (passwordProtectCheckBox.IsChecked == true && passwordProtect.ToLower().Equals("false"))
{
var passwordDialog = new PasswordWindow();

if (passwordDialog.ShowDialog() == true && passwordDialog.PasswordText != "")
{
Password = passwordDialog.PasswordText;
settingsFile.Write("PasswordProtect", "true", "Settings");
}
else
{
Password = "";
}
}
else if (passwordProtectCheckBox.IsChecked == false && passwordProtect.ToLower().Equals("true"))
{
MessageBoxResult messageBoxResult = MessageBox.Show("Are you sure you want to decrypt your data file?", "Confirm", MessageBoxButton.YesNo, MessageBoxImage.Warning);

if (messageBoxResult == MessageBoxResult.Yes)
{
var passwordDialog = new PasswordWindow();

if (passwordDialog.ShowDialog() == true)
{
messageBoxResult = MessageBoxResult.OK;

while (messageBoxResult == MessageBoxResult.OK)
{
try
{
Utils.PasswordDeserialize("info.dat", passwordDialog.PasswordText);
messageBoxResult = MessageBoxResult.None;
}
catch (Exception e)
{
Console.WriteLine(e.Message);
messageBoxResult = MessageBox.Show("Invalid Password", "Invalid", MessageBoxButton.OKCancel, MessageBoxImage.Warning);

if (messageBoxResult == MessageBoxResult.Cancel)
{
passwordProtectCheckBox.IsChecked = true;
return;
}

passwordDialog = new PasswordWindow();
passwordDialog.ShowDialog();
}
}
}
}
else
{
passwordProtectCheckBox.IsChecked = true;
return;
}

settingsFile.Write("PasswordProtect", "false", "Settings");
Password = "";
Decrypt = true;
}
else if (passwordProtectCheckBox.IsChecked == false)
settingsFile.Write("PasswordProtect", "false", "Settings");

settingsFile.Write("AccountsPerRow", apr, "Settings");

if (startupCheckBox.IsChecked == true)
{
settingsFile.Write("StartWithWindows", "True", "Settings");
settingsFile.Write("StartWithWindows", "true", "Settings");

WshShell shell = new WshShell();
string shortcutAddress = Environment.GetFolderPath(Environment.SpecialFolder.Startup) + @"\SAM.lnk";
Expand All @@ -103,23 +189,28 @@ private void SaveSettings(string apr)
if (System.IO.File.Exists(filePath))
System.IO.File.Delete(filePath);

settingsFile.Write("StartWithWindows", "False", "Settings");
settingsFile.Write("StartWithWindows", "false", "Settings");
}

if (startupMinCheckBox.IsChecked == true)
settingsFile.Write("StartMinimized", "True", "Settings");
settingsFile.Write("StartMinimized", "true", "Settings");
else
settingsFile.Write("StartMinimized", "false", "Settings");

if (minimizeToTrayCheckBox.IsChecked == true)
settingsFile.Write("MinimizeToTray", "true", "Settings");
else
settingsFile.Write("StartMinimized", "False", "Settings");
settingsFile.Write("MinimizeToTray", "false", "Settings");

if (mostRecentCheckBox.IsChecked == true)
settingsFile.Write("Recent", "True", "AutoLog");
settingsFile.Write("Recent", "true", "AutoLog");
else
settingsFile.Write("Recent", "False", "AutoLog");
settingsFile.Write("Recent", "false", "AutoLog");

if (selectedAccountCheckBox.IsChecked == true)
settingsFile.Write("Selected", "True", "AutoLog");
settingsFile.Write("Selected", "true", "AutoLog");
else
settingsFile.Write("Selected", "False", "AutoLog");
settingsFile.Write("Selected", "false", "AutoLog");

settingsFile.Write("Steam", SteamPathTextBox.Text, "Settings");
}
Expand Down Expand Up @@ -247,5 +338,15 @@ private void AutoPathButton_Click(object sender, RoutedEventArgs e)
MessageBox.Show(m.Message);
}
}

private void PasswordProtectCheckBox_Checked(object sender, RoutedEventArgs e)
{

}

private void PasswordProtectCheckBox_Unchecked(object sender, RoutedEventArgs e)
{

}
}
}
Loading

0 comments on commit 6fb40a6

Please sign in to comment.