Skip to content

Commit

Permalink
Merge pull request #269 from gandalan/9963_optimize_login
Browse files Browse the repository at this point in the history
#9963 Add toggle to show/hide password in LoginWindow_v2
  • Loading branch information
gdl-drw authored Aug 22, 2023
2 parents 780cd58 + 92436be commit 86b0401
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 6 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,13 @@ private void SetOrClearMessage(string v1, bool v2, string v3)
public bool ShowLoggedInEnvironments { get; set; }
public bool ShowLoginFields => !ShowLoggedInEnvironments;
public string StatusText { get; set; }


public string PlainPassword { get; set; }
public bool ShowPlainPassword { get; set; } = false;
public bool HidePlainPassword => !ShowPlainPassword;
public string PasswordInputWarning { get; set; }
public bool ShowPasswordInputWarning { get; set; }

public LoginWindowViewModel_v2(IWebApiConfig webApiSettings)
{
AlleEnvironments = WebApiConfigurations.GetAll();
Expand Down
21 changes: 16 additions & 5 deletions Gandalan.IDAS.WebApi.Client.Wpf/Dialogs/LoginWindow_v2.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@
</Style>
</ResourceDictionary>
</Window.Resources>



<StackPanel Orientation="Vertical">
<StackPanel Orientation="Horizontal" Margin="40,30,40,40">
Expand Down Expand Up @@ -77,7 +75,6 @@
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>


<Label Visibility="{Binding ShowServerSelection, Converter={StaticResource BoolToVis}}" Grid.Column="0" Grid.Row="1" Content="Environment:" VerticalAlignment="Center"></Label>
<DockPanel Grid.Column="1" Grid.Row="1" Visibility="{Binding ShowServerSelection, Converter={StaticResource BoolToVis}}" >
<CheckBox IsChecked="{Binding EnvAlsDefault, Mode=TwoWay}" DockPanel.Dock="Right" Content="Als Standard setzen" VerticalContentAlignment="Center" VerticalAlignment="Center" Margin="5,5,10,5" Padding="2"/>
Expand All @@ -88,7 +85,22 @@
<TextBox Name="userNameTextBox" Grid.Column="1" Grid.Row="2" Text="{Binding UserName}" Margin="5" Padding="5"/>

<Label Grid.Column="0" Grid.Row="3" Content="Passwort:" VerticalAlignment="Center"></Label>
<PasswordBox x:Name="passwordBox" Grid.Column="1" Grid.Row="3" Margin="5" Padding="5"/>
<Grid Grid.Column="1" Grid.Row="3" >
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<PasswordBox x:Name="passwordBox" Margin="5" Padding="5" Visibility="{Binding HidePlainPassword, Converter={StaticResource BoolToVis}}" VerticalContentAlignment="Center"/>
<TextBox x:Name="plainPasswordBox" Margin="5" Padding="5" Text="{Binding PlainPassword, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" TextChanged="plainPasswordBox_TextChanged" Visibility="{Binding ShowPlainPassword, Converter={StaticResource BoolToVis}}" VerticalContentAlignment="Center"/>
<Button x:Name="togglePasswordButton" Grid.Column="1" Margin="0,5,5,5" Padding="5" Click="TogglePassword_Click">
<Image x:Name="togglePasswordButtonImage" Source="pack://application:,,,/GDL.IDAS.WebApi.Client.WPF;component/Assets/Icons/view-off.png" Width="18" Height="18"></Image>
</Button>
<TextBlock Grid.Row="1" Margin="5,0,0,0" Text="{Binding PasswordInputWarning}" Foreground="Orange" d:Text="Feststelltaste ist aktiviert."/>
</Grid>

<CheckBox x:Name="checkBoxAuthToken" IsChecked="{Binding SaveCredentials}" Grid.Column="1" Grid.Row="4" Content="Anmeldung merken" VerticalContentAlignment="Center" Margin="5,5,10,5" Padding="2"/>

Expand All @@ -112,7 +124,6 @@
</Button>
</Grid>


<!--<StackPanel Grid.Column="1" Grid.Row="5" Orientation="Horizontal" Margin="0,10,0,0">
<Button Content="Anmelden" IsDefault="True" Click="anmeldenButtonClick" Margin="5" Padding="5"/>
<Button Content="Abbrechen" IsCancel="True" Click="abbrechenButton_Click" Margin="5" Padding="5"/>
Expand Down
43 changes: 43 additions & 0 deletions Gandalan.IDAS.WebApi.Client.Wpf/Dialogs/LoginWindow_v2.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media.Imaging;

namespace Gandalan.IDAS.WebApi.Client.Wpf.Dialogs
{
Expand Down Expand Up @@ -199,6 +200,48 @@ private void Window_KeyDown(object sender, KeyEventArgs e)
{
_viewModel.ShowServerSelection = !_viewModel.ShowServerSelection;
}
if (Keyboard.IsKeyToggled(Key.CapsLock) || !Keyboard.IsKeyToggled(Key.NumLock))
{
_viewModel.ShowPasswordInputWarning = true;
_viewModel.PasswordInputWarning = "";
if (Keyboard.IsKeyToggled(Key.CapsLock))
{
_viewModel.PasswordInputWarning += "Feststelltaste ist aktiviert. ";
}
if (!Keyboard.IsKeyToggled(Key.NumLock))
{
_viewModel.PasswordInputWarning += "Numlock ist nicht aktiviert. ";
}
}
else
{
if (_viewModel.ShowPasswordInputWarning) // only reset if warning is shown
{
_viewModel.ShowPasswordInputWarning = false;
_viewModel.PasswordInputWarning = null;
}
}
}

private void TogglePassword_Click(object sender, RoutedEventArgs e)
{
_viewModel.ShowPlainPassword = !_viewModel.ShowPlainPassword;
togglePasswordButton.ToolTip = _viewModel.ShowPlainPassword ? "Verbergen" : "Anzeigen";
if (!_viewModel.ShowPlainPassword)
{
passwordBox.Password = _viewModel.PlainPassword;
togglePasswordButtonImage.Source = new BitmapImage(new Uri("pack://application:,,,/GDL.IDAS.WebApi.Client.WPF;component/Assets/Icons/view-off.png"));
}
else
{
_viewModel.PlainPassword = passwordBox.Password;
togglePasswordButtonImage.Source = new BitmapImage(new Uri("pack://application:,,,/GDL.IDAS.WebApi.Client.WPF;component/Assets/Icons/view-1.png"));
}
}

private void plainPasswordBox_TextChanged(object sender, TextChangedEventArgs e)
{
passwordBox.Password = plainPasswordBox.Text;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
<NoWarn>1591</NoWarn>
</PropertyGroup>
<ItemGroup>
<None Remove="Assets\Icons\view-1.png" />
<None Remove="Assets\Icons\view-off.png" />
<None Remove="Assets\Neher\Logo.png" />
</ItemGroup>
<ItemGroup>
Expand All @@ -36,6 +38,8 @@
<Reference Include="WindowsBase" />
</ItemGroup>
<ItemGroup>
<Resource Include="Assets\Icons\view-1.png" />
<Resource Include="Assets\Icons\view-off.png" />
<Resource Include="Assets\Neher\Logo.png" />
</ItemGroup>
</Project>

0 comments on commit 86b0401

Please sign in to comment.