diff --git a/.vs/Server Dashboard/DesignTimeBuild/.dtbcache.v2 b/.vs/Server Dashboard/DesignTimeBuild/.dtbcache.v2 index be66e0f..76a16cb 100644 Binary files a/.vs/Server Dashboard/DesignTimeBuild/.dtbcache.v2 and b/.vs/Server Dashboard/DesignTimeBuild/.dtbcache.v2 differ diff --git a/.vs/Server Dashboard/v16/.suo b/.vs/Server Dashboard/v16/.suo index 67dfa8c..e147453 100644 Binary files a/.vs/Server Dashboard/v16/.suo and b/.vs/Server Dashboard/v16/.suo differ diff --git a/Server Dashboard/App.config b/Server Dashboard/App.config new file mode 100644 index 0000000..a4ef717 --- /dev/null +++ b/Server Dashboard/App.config @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/Server Dashboard/App.xaml b/Server Dashboard/App.xaml index 36df237..e4da259 100644 --- a/Server Dashboard/App.xaml +++ b/Server Dashboard/App.xaml @@ -12,8 +12,8 @@ - - + + @@ -26,6 +26,8 @@ + + + + diff --git a/Server Dashboard/AttachedProperty/BaseAttachedProperty.cs b/Server Dashboard/AttachedProperty/BaseAttachedProperty.cs new file mode 100644 index 0000000..55ae5e3 --- /dev/null +++ b/Server Dashboard/AttachedProperty/BaseAttachedProperty.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Windows; + +namespace Server_Dashboard { + public abstract class BaseAttachedProperty + where Parent : BaseAttachedProperty, new() { + public event Action ValueChanged = (sender, e) => { }; + public static Parent Instance { get; private set; } = new Parent(); + public static readonly DependencyProperty ValueProperty = DependencyProperty.RegisterAttached("Value", typeof(Property), typeof(BaseAttachedProperty), new PropertyMetadata(new PropertyChangedCallback(OnValuePropertyChanged))); + private static void OnValuePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { + Instance.OnValueChanged(d, e); + Instance.ValueChanged(d, e); + } + public static Property GetValue(DependencyObject d) => (Property)d.GetValue(ValueProperty); + public static void SetValue(DependencyObject d, Property value) => d.SetValue(ValueProperty, value); + public virtual void OnValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) { } + } +} diff --git a/Server Dashboard/AttachedProperty/PasswordBoxProperties.cs b/Server Dashboard/AttachedProperty/PasswordBoxProperties.cs new file mode 100644 index 0000000..c564c2d --- /dev/null +++ b/Server Dashboard/AttachedProperty/PasswordBoxProperties.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Windows; +using System.Windows.Controls; + +namespace Server_Dashboard { + public class MonitorPasswordProperty : BaseAttachedProperty { + public override void OnValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) { + var passwordBox = sender as PasswordBox; + if (passwordBox == null) + return; + passwordBox.PasswordChanged -= PasswordBox_PasswordChanged; + + if ((bool)e.NewValue) { + HasTextProperty.SetValue(passwordBox); + passwordBox.PasswordChanged += PasswordBox_PasswordChanged; + } + } + + private void PasswordBox_PasswordChanged(object sender, RoutedEventArgs e) { + HasTextProperty.SetValue((PasswordBox)sender); + } + } + public class HasTextProperty : BaseAttachedProperty { + public static void SetValue(DependencyObject sender) { + SetValue(sender, ((PasswordBox)sender).SecurePassword.Length < 1); + } + } +} diff --git a/Server Dashboard/Database/DatabaseHandler.cs b/Server Dashboard/Database/DatabaseHandler.cs index 1b2bdf0..d7459e7 100644 --- a/Server Dashboard/Database/DatabaseHandler.cs +++ b/Server Dashboard/Database/DatabaseHandler.cs @@ -2,19 +2,37 @@ using System; using System.Collections.Generic; using System.Configuration; +using System.Data; using System.Data.SqlClient; using System.Reflection; namespace Server_Dashboard { - class DatabaseHandler { + public static class DatabaseHandler { + + public static bool CheckLogin(string uname, string passwd) { + string valid = "False"; + ConnectToDatabase(con => { + string query = "EXEC ValidateUserLogin @Username = @uname, @Password = @passwd, @Valid = @valid OUTPUT"; + using (SqlCommand com = new SqlCommand(query, con)) { + com.Parameters.AddWithValue("@uname", uname); + com.Parameters.AddWithValue("@passwd", passwd); + com.Parameters.Add("@valid", SqlDbType.NVarChar, 250); + com.Parameters["@valid"].Direction = ParameterDirection.Output; + com.ExecuteNonQuery(); + valid = Convert.ToString(com.Parameters["@Valid"].Value); + } + }); + return Convert.ToBoolean(valid); + } + #region Private methods /// /// Opens a database connection /// /// Callback type SqlConnection /// - private SqlConnection ConnectToDatabase(Action callback) { - using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["Co2AuswertungDB"].ConnectionString)) { + private static SqlConnection ConnectToDatabase(Action callback) { + using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ServerDashboardDB"].ConnectionString)) { try { con.Open(); callback(con); diff --git a/Server Dashboard/LoginWindow.xaml b/Server Dashboard/LoginWindow.xaml index fe4b101..827960b 100644 --- a/Server Dashboard/LoginWindow.xaml +++ b/Server Dashboard/LoginWindow.xaml @@ -5,6 +5,7 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:i="http://schemas.microsoft.com/xaml/behaviors" xmlns:local="clr-namespace:Server_Dashboard" + x:Name="Login" mc:Ignorable="d" Title="Server Dashboard" Height="700" Width="500" WindowStyle="None" ResizeMode="NoResize" Background="Transparent" AllowsTransparency="True"> @@ -15,7 +16,8 @@ - + + @@ -61,11 +63,12 @@ - - + + -