changed database and implemented passwordless login
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -6,3 +6,4 @@ C:\Users\Crylia\Documents\Git\Server Dashboard\Server Dashboard Socket\obj\Debug
|
|||||||
C:\Users\Crylia\Documents\Git\Server Dashboard\Server Dashboard Socket\obj\Debug\netcoreapp3.1\Server Dashboard Socket.csproj.CoreCompileInputs.cache
|
C:\Users\Crylia\Documents\Git\Server Dashboard\Server Dashboard Socket\obj\Debug\netcoreapp3.1\Server Dashboard Socket.csproj.CoreCompileInputs.cache
|
||||||
C:\Users\Crylia\Documents\Git\Server Dashboard\Server Dashboard Socket\obj\Debug\netcoreapp3.1\Server Dashboard Socket.dll
|
C:\Users\Crylia\Documents\Git\Server Dashboard\Server Dashboard Socket\obj\Debug\netcoreapp3.1\Server Dashboard Socket.dll
|
||||||
C:\Users\Crylia\Documents\Git\Server Dashboard\Server Dashboard Socket\obj\Debug\netcoreapp3.1\Server Dashboard Socket.pdb
|
C:\Users\Crylia\Documents\Git\Server Dashboard\Server Dashboard Socket\obj\Debug\netcoreapp3.1\Server Dashboard Socket.pdb
|
||||||
|
C:\Users\Crylia\Documents\Git\Server Dashboard\Server Dashboard Socket\obj\Debug\netcoreapp3.1\Server Dashboard Socket.csprojAssemblyReference.cache
|
||||||
|
|||||||
Binary file not shown.
@@ -35,71 +35,64 @@ namespace Server_Dashboard {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool CheckCookie(string cookie, string username) {
|
public static int CheckCookie(string cookie, string username) {
|
||||||
string valid = "False";
|
|
||||||
ConnectToDatabase(con => {
|
|
||||||
string query = "EXEC CheckUserCookie @Cookie = @cookie, @UserName = @username, @Valid = @valid OUTPUT";
|
|
||||||
using (SqlCommand com = new SqlCommand(query, con)) {
|
|
||||||
com.Parameters.AddWithValue("@cookie", cookie);
|
|
||||||
com.Parameters.AddWithValue("@username", username);
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool DeleteCookie(string username) {
|
|
||||||
string valid = "False";
|
|
||||||
ConnectToDatabase(con => {
|
|
||||||
string query = "EXEC DeleteUserCookie @Username = @username, @ResponseMessage = @response OUTPUT";
|
|
||||||
using (SqlCommand com = new SqlCommand(query, con)) {
|
|
||||||
com.Parameters.AddWithValue("@username", username);
|
|
||||||
com.Parameters.Add("@response", SqlDbType.NVarChar, 250);
|
|
||||||
com.Parameters["@response"].Direction = ParameterDirection.Output;
|
|
||||||
com.ExecuteNonQuery();
|
|
||||||
valid = Convert.ToString(com.Parameters["@ResponseMessage"].Value);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return Convert.ToBoolean(valid);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool AddCookie(string cookie, string username) {
|
|
||||||
string valid = "False";
|
|
||||||
ConnectToDatabase(con => {
|
|
||||||
string query = "EXEC AddCookieToUser @Cookie = @cookie, @UserName = @username, @ResponseMessage = @response OUTPUT";
|
|
||||||
using (SqlCommand com = new SqlCommand(query, con)) {
|
|
||||||
com.Parameters.AddWithValue("@cookie", cookie);
|
|
||||||
com.Parameters.AddWithValue("@username", username);
|
|
||||||
com.Parameters.Add("@response", SqlDbType.NVarChar, 250);
|
|
||||||
com.Parameters["@response"].Direction = ParameterDirection.Output;
|
|
||||||
com.ExecuteNonQuery();
|
|
||||||
valid = Convert.ToString(com.Parameters["@ResponseMessage"].Value);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return Convert.ToBoolean(valid);
|
|
||||||
}
|
|
||||||
|
|
||||||
#region Private methods
|
|
||||||
/// <summary>
|
|
||||||
/// Opens a database connection
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="callback">Callback type SqlConnection</param>
|
|
||||||
/// <returns></returns>
|
|
||||||
private static SqlConnection ConnectToDatabase(Action<SqlConnection> callback) {
|
|
||||||
using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ServerDashboardDB"].ConnectionString)) {
|
using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ServerDashboardDB"].ConnectionString)) {
|
||||||
try {
|
try {
|
||||||
con.Open();
|
con.Open();
|
||||||
callback(con);
|
string query = "EXEC CheckUserCookie @Cookie = @cookie, @UserName = @username, @Valid = @valid OUTPUT";
|
||||||
con.Close();
|
using (SqlCommand com = new SqlCommand(query, con)) {
|
||||||
|
com.Parameters.AddWithValue("@cookie", cookie);
|
||||||
|
com.Parameters.AddWithValue("@username", username);
|
||||||
|
com.Parameters.Add("@valid", SqlDbType.Bit);
|
||||||
|
com.Parameters["@valid"].Direction = ParameterDirection.Output;
|
||||||
|
com.ExecuteNonQuery();
|
||||||
|
return Convert.ToInt32(com.Parameters["@Valid"].Value);
|
||||||
|
}
|
||||||
} catch (SqlException ex) {
|
} catch (SqlException ex) {
|
||||||
return null;
|
return ex.Number;
|
||||||
|
} finally {
|
||||||
|
con.Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void DeleteCookie(string username) {
|
||||||
|
using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ServerDashboardDB"].ConnectionString)) {
|
||||||
|
try {
|
||||||
|
con.Open();
|
||||||
|
string query = "EXEC DeleteUserCookie @Username = @username, @ResponseMessage = @response OUTPUT";
|
||||||
|
using (SqlCommand com = new SqlCommand(query, con)) {
|
||||||
|
com.Parameters.AddWithValue("@username", username);
|
||||||
|
com.Parameters.Add("@response", SqlDbType.NVarChar, 250);
|
||||||
|
com.Parameters["@response"].Direction = ParameterDirection.Output;
|
||||||
|
com.ExecuteNonQuery();
|
||||||
|
}
|
||||||
|
} catch (SqlException ex) {
|
||||||
|
} finally {
|
||||||
|
con.Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int AddCookie(string cookie, string username) {
|
||||||
|
using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ServerDashboardDB"].ConnectionString)) {
|
||||||
|
try {
|
||||||
|
con.Open();
|
||||||
|
string query = "EXEC AddCookieToUser @Cookie = @cookie, @UserName = @username, @ResponseMessage = @response OUTPUT";
|
||||||
|
using (SqlCommand com = new SqlCommand(query, con)) {
|
||||||
|
com.Parameters.AddWithValue("@cookie", cookie);
|
||||||
|
com.Parameters.AddWithValue("@username", username);
|
||||||
|
com.Parameters.Add("@response", SqlDbType.NVarChar, 250);
|
||||||
|
com.Parameters["@response"].Direction = ParameterDirection.Output;
|
||||||
|
com.ExecuteNonQuery();
|
||||||
|
return Convert.ToInt32(com.Parameters["@ResponseMessage"].Value);
|
||||||
|
}
|
||||||
|
} catch (SqlException ex) {
|
||||||
|
return ex.Number;
|
||||||
|
} finally {
|
||||||
|
con.Close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
#endregion
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
12
Server Dashboard/Properties/Settings.Designer.cs
generated
12
Server Dashboard/Properties/Settings.Designer.cs
generated
@@ -58,5 +58,17 @@ namespace Server_Dashboard.Properties {
|
|||||||
this["RememberMe"] = value;
|
this["RememberMe"] = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[global::System.Configuration.UserScopedSettingAttribute()]
|
||||||
|
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||||
|
[global::System.Configuration.DefaultSettingValueAttribute("")]
|
||||||
|
public string Password {
|
||||||
|
get {
|
||||||
|
return ((string)(this["Password"]));
|
||||||
|
}
|
||||||
|
set {
|
||||||
|
this["Password"] = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,5 +11,8 @@
|
|||||||
<Setting Name="RememberMe" Type="System.Boolean" Scope="User">
|
<Setting Name="RememberMe" Type="System.Boolean" Scope="User">
|
||||||
<Value Profile="(Default)">False</Value>
|
<Value Profile="(Default)">False</Value>
|
||||||
</Setting>
|
</Setting>
|
||||||
|
<Setting Name="Password" Type="System.String" Scope="User">
|
||||||
|
<Value Profile="(Default)" />
|
||||||
|
</Setting>
|
||||||
</Settings>
|
</Settings>
|
||||||
</SettingsFile>
|
</SettingsFile>
|
||||||
@@ -66,8 +66,12 @@ namespace Server_Dashboard {
|
|||||||
|
|
||||||
private async void LoginAsync(object parameter) {
|
private async void LoginAsync(object parameter) {
|
||||||
if (!String.IsNullOrWhiteSpace(Username) && !String.IsNullOrWhiteSpace((parameter as IHavePassword).SecurePassword.Unsecure())) {
|
if (!String.IsNullOrWhiteSpace(Username) && !String.IsNullOrWhiteSpace((parameter as IHavePassword).SecurePassword.Unsecure())) {
|
||||||
|
int result = 0;
|
||||||
|
if (RememberUser && !String.IsNullOrEmpty(Settings.Default.Username) && !String.IsNullOrEmpty(Settings.Default.Cookies) && Settings.Default.Password.Length == 6) {
|
||||||
|
result = await Task.Run(() => DatabaseHandler.CheckCookie(Settings.Default.Cookies, Username));
|
||||||
|
}
|
||||||
Loading = "Visible";
|
Loading = "Visible";
|
||||||
int result = await Task.Run(() => DatabaseHandler.CheckLogin(Username, (parameter as IHavePassword).SecurePassword.Unsecure()));
|
result = await Task.Run(() => DatabaseHandler.CheckLogin(Username, (parameter as IHavePassword).SecurePassword.Unsecure()));
|
||||||
Loading = "Hidden";
|
Loading = "Hidden";
|
||||||
switch (result) {
|
switch (result) {
|
||||||
case 0:
|
case 0:
|
||||||
@@ -81,6 +85,7 @@ namespace Server_Dashboard {
|
|||||||
Settings.Default.Cookies = null;
|
Settings.Default.Cookies = null;
|
||||||
Settings.Default.Username = "";
|
Settings.Default.Username = "";
|
||||||
Settings.Default.RememberMe = false;
|
Settings.Default.RememberMe = false;
|
||||||
|
Settings.Default.Password = "";
|
||||||
Settings.Default.Save();
|
Settings.Default.Save();
|
||||||
DatabaseHandler.DeleteCookie(Username);
|
DatabaseHandler.DeleteCookie(Username);
|
||||||
}
|
}
|
||||||
@@ -89,6 +94,7 @@ namespace Server_Dashboard {
|
|||||||
Settings.Default.Cookies = guid;
|
Settings.Default.Cookies = guid;
|
||||||
Settings.Default.Username = Username;
|
Settings.Default.Username = Username;
|
||||||
Settings.Default.RememberMe = true;
|
Settings.Default.RememberMe = true;
|
||||||
|
Settings.Default.Password = "*****";
|
||||||
Settings.Default.Save();
|
Settings.Default.Save();
|
||||||
DatabaseHandler.AddCookie(Username, guid);
|
DatabaseHandler.AddCookie(Username, guid);
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
@@ -1,4 +1,5 @@
|
|||||||
#pragma checksum "..\..\..\LoginWindow.xaml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "BC333A5F7B9E8D68E824FFFBFE4539E4AA85365F"
|
// Updated by XamlIntelliSenseFileGenerator 05.08.2021 22:10:48
|
||||||
|
#pragma checksum "..\..\..\LoginWindow.xaml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "BC333A5F7B9E8D68E824FFFBFE4539E4AA85365F"
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
// <auto-generated>
|
// <auto-generated>
|
||||||
// This code was generated by a tool.
|
// This code was generated by a tool.
|
||||||
@@ -40,47 +41,42 @@ using System.Windows.Shell;
|
|||||||
|
|
||||||
|
|
||||||
namespace Server_Dashboard {
|
namespace Server_Dashboard {
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// LoginWindow
|
/// LoginWindow
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public partial class LoginWindow : System.Windows.Window, System.Windows.Markup.IComponentConnector {
|
public partial class LoginWindow : System.Windows.Window, System.Windows.Markup.IComponentConnector {
|
||||||
|
|
||||||
|
#line default
|
||||||
#line 9 "..\..\..\LoginWindow.xaml"
|
#line hidden
|
||||||
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
|
|
||||||
internal Server_Dashboard.LoginWindow Login;
|
|
||||||
|
#line 130 "..\..\..\LoginWindow.xaml"
|
||||||
#line default
|
|
||||||
#line hidden
|
|
||||||
|
|
||||||
|
|
||||||
#line 130 "..\..\..\LoginWindow.xaml"
|
|
||||||
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
|
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
|
||||||
internal System.Windows.Controls.TextBox UserName;
|
internal System.Windows.Controls.TextBox UserName;
|
||||||
|
|
||||||
#line default
|
#line default
|
||||||
#line hidden
|
#line hidden
|
||||||
|
|
||||||
|
|
||||||
#line 174 "..\..\..\LoginWindow.xaml"
|
#line 174 "..\..\..\LoginWindow.xaml"
|
||||||
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
|
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
|
||||||
internal System.Windows.Controls.PasswordBox Password;
|
internal System.Windows.Controls.PasswordBox Password;
|
||||||
|
|
||||||
#line default
|
#line default
|
||||||
#line hidden
|
#line hidden
|
||||||
|
|
||||||
|
|
||||||
#line 185 "..\..\..\LoginWindow.xaml"
|
#line 185 "..\..\..\LoginWindow.xaml"
|
||||||
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
|
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
|
||||||
internal System.Windows.Controls.TextBlock PasswordHint;
|
internal System.Windows.Controls.TextBlock PasswordHint;
|
||||||
|
|
||||||
#line default
|
#line default
|
||||||
#line hidden
|
#line hidden
|
||||||
|
|
||||||
private bool _contentLoaded;
|
private bool _contentLoaded;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// InitializeComponent
|
/// InitializeComponent
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -92,21 +88,21 @@ namespace Server_Dashboard {
|
|||||||
}
|
}
|
||||||
_contentLoaded = true;
|
_contentLoaded = true;
|
||||||
System.Uri resourceLocater = new System.Uri("/Server Dashboard;component/loginwindow.xaml", System.UriKind.Relative);
|
System.Uri resourceLocater = new System.Uri("/Server Dashboard;component/loginwindow.xaml", System.UriKind.Relative);
|
||||||
|
|
||||||
#line 1 "..\..\..\LoginWindow.xaml"
|
#line 1 "..\..\..\LoginWindow.xaml"
|
||||||
System.Windows.Application.LoadComponent(this, resourceLocater);
|
System.Windows.Application.LoadComponent(this, resourceLocater);
|
||||||
|
|
||||||
#line default
|
#line default
|
||||||
#line hidden
|
#line hidden
|
||||||
}
|
}
|
||||||
|
|
||||||
[System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
[System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||||
[System.CodeDom.Compiler.GeneratedCodeAttribute("PresentationBuildTasks", "5.0.4.0")]
|
[System.CodeDom.Compiler.GeneratedCodeAttribute("PresentationBuildTasks", "5.0.4.0")]
|
||||||
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
|
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
|
||||||
internal System.Delegate _CreateDelegate(System.Type delegateType, string handler) {
|
internal System.Delegate _CreateDelegate(System.Type delegateType, string handler) {
|
||||||
return System.Delegate.CreateDelegate(delegateType, this, handler);
|
return System.Delegate.CreateDelegate(delegateType, this, handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
[System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
[System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||||
[System.CodeDom.Compiler.GeneratedCodeAttribute("PresentationBuildTasks", "5.0.4.0")]
|
[System.CodeDom.Compiler.GeneratedCodeAttribute("PresentationBuildTasks", "5.0.4.0")]
|
||||||
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
|
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
|
||||||
@@ -114,23 +110,24 @@ namespace Server_Dashboard {
|
|||||||
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity")]
|
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity")]
|
||||||
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1800:DoNotCastUnnecessarily")]
|
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1800:DoNotCastUnnecessarily")]
|
||||||
void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target) {
|
void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target) {
|
||||||
switch (connectionId)
|
switch (connectionId) {
|
||||||
{
|
case 1:
|
||||||
case 1:
|
this.Login = ((Server_Dashboard.LoginWindow)(target));
|
||||||
this.Login = ((Server_Dashboard.LoginWindow)(target));
|
return;
|
||||||
return;
|
case 2:
|
||||||
case 2:
|
this.UserName = ((System.Windows.Controls.TextBox)(target));
|
||||||
this.UserName = ((System.Windows.Controls.TextBox)(target));
|
return;
|
||||||
return;
|
case 3:
|
||||||
case 3:
|
this.Password = ((System.Windows.Controls.PasswordBox)(target));
|
||||||
this.Password = ((System.Windows.Controls.PasswordBox)(target));
|
return;
|
||||||
return;
|
case 4:
|
||||||
case 4:
|
this.PasswordHint = ((System.Windows.Controls.TextBlock)(target));
|
||||||
this.PasswordHint = ((System.Windows.Controls.TextBlock)(target));
|
return;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
this._contentLoaded = true;
|
this._contentLoaded = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal System.Windows.Window Login;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -16,5 +16,5 @@ C:\Users\Crylia\Documents\Git\Server Dashboard\Server Dashboard\App.xaml
|
|||||||
2061472260849
|
2061472260849
|
||||||
Controls\Dashboard\CRUD Popup\CreateModulePopup.xaml;Controls\DoubleRoundProgressBar\DoubleRoundProgressBar.xaml;Controls\HalfRoundProgressBar\HalfRoundProgressBar.xaml;Controls\LoadingIndicator\LoadingIndicator.xaml;Controls\ServerModules\ServerModule.xaml;LoginWindow.xaml;Views\DashboardPages\MainDashboardPage.xaml;Views\DashboardWindow.xaml;
|
Controls\Dashboard\CRUD Popup\CreateModulePopup.xaml;Controls\DoubleRoundProgressBar\DoubleRoundProgressBar.xaml;Controls\HalfRoundProgressBar\HalfRoundProgressBar.xaml;Controls\LoadingIndicator\LoadingIndicator.xaml;Controls\ServerModules\ServerModule.xaml;LoginWindow.xaml;Views\DashboardPages\MainDashboardPage.xaml;Views\DashboardWindow.xaml;
|
||||||
|
|
||||||
True
|
False
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +0,0 @@
|
|||||||
|
|
||||||
|
|
||||||
FC:\Users\Crylia\Documents\Git\Server Dashboard\Server Dashboard\Controls\LoadingIndicator\LoadingIndicator.xaml;;
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user