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.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.csprojAssemblyReference.cache
|
||||
|
||||
Binary file not shown.
@@ -35,71 +35,64 @@ namespace Server_Dashboard {
|
||||
}
|
||||
}
|
||||
|
||||
public static bool 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) {
|
||||
public static int CheckCookie(string cookie, string username) {
|
||||
using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ServerDashboardDB"].ConnectionString)) {
|
||||
try {
|
||||
con.Open();
|
||||
callback(con);
|
||||
con.Close();
|
||||
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.Bit);
|
||||
com.Parameters["@valid"].Direction = ParameterDirection.Output;
|
||||
com.ExecuteNonQuery();
|
||||
return Convert.ToInt32(com.Parameters["@Valid"].Value);
|
||||
}
|
||||
} 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;
|
||||
}
|
||||
}
|
||||
|
||||
[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">
|
||||
<Value Profile="(Default)">False</Value>
|
||||
</Setting>
|
||||
<Setting Name="Password" Type="System.String" Scope="User">
|
||||
<Value Profile="(Default)" />
|
||||
</Setting>
|
||||
</Settings>
|
||||
</SettingsFile>
|
||||
@@ -66,8 +66,12 @@ namespace Server_Dashboard {
|
||||
|
||||
private async void LoginAsync(object parameter) {
|
||||
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";
|
||||
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";
|
||||
switch (result) {
|
||||
case 0:
|
||||
@@ -81,6 +85,7 @@ namespace Server_Dashboard {
|
||||
Settings.Default.Cookies = null;
|
||||
Settings.Default.Username = "";
|
||||
Settings.Default.RememberMe = false;
|
||||
Settings.Default.Password = "";
|
||||
Settings.Default.Save();
|
||||
DatabaseHandler.DeleteCookie(Username);
|
||||
}
|
||||
@@ -89,6 +94,7 @@ namespace Server_Dashboard {
|
||||
Settings.Default.Cookies = guid;
|
||||
Settings.Default.Username = Username;
|
||||
Settings.Default.RememberMe = true;
|
||||
Settings.Default.Password = "*****";
|
||||
Settings.Default.Save();
|
||||
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>
|
||||
// This code was generated by a tool.
|
||||
@@ -47,37 +48,32 @@ namespace Server_Dashboard {
|
||||
/// </summary>
|
||||
public partial class LoginWindow : System.Windows.Window, System.Windows.Markup.IComponentConnector {
|
||||
|
||||
|
||||
#line 9 "..\..\..\LoginWindow.xaml"
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
|
||||
internal Server_Dashboard.LoginWindow Login;
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
#line default
|
||||
#line hidden
|
||||
|
||||
|
||||
#line 130 "..\..\..\LoginWindow.xaml"
|
||||
#line 130 "..\..\..\LoginWindow.xaml"
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
|
||||
internal System.Windows.Controls.TextBox UserName;
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
#line default
|
||||
#line hidden
|
||||
|
||||
|
||||
#line 174 "..\..\..\LoginWindow.xaml"
|
||||
#line 174 "..\..\..\LoginWindow.xaml"
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
|
||||
internal System.Windows.Controls.PasswordBox Password;
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
#line default
|
||||
#line hidden
|
||||
|
||||
|
||||
#line 185 "..\..\..\LoginWindow.xaml"
|
||||
#line 185 "..\..\..\LoginWindow.xaml"
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
|
||||
internal System.Windows.Controls.TextBlock PasswordHint;
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
#line default
|
||||
#line hidden
|
||||
|
||||
private bool _contentLoaded;
|
||||
|
||||
@@ -93,11 +89,11 @@ namespace Server_Dashboard {
|
||||
_contentLoaded = true;
|
||||
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);
|
||||
|
||||
#line default
|
||||
#line hidden
|
||||
#line default
|
||||
#line hidden
|
||||
}
|
||||
|
||||
[System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
@@ -114,23 +110,24 @@ namespace Server_Dashboard {
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity")]
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1800:DoNotCastUnnecessarily")]
|
||||
void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target) {
|
||||
switch (connectionId)
|
||||
{
|
||||
case 1:
|
||||
this.Login = ((Server_Dashboard.LoginWindow)(target));
|
||||
return;
|
||||
case 2:
|
||||
this.UserName = ((System.Windows.Controls.TextBox)(target));
|
||||
return;
|
||||
case 3:
|
||||
this.Password = ((System.Windows.Controls.PasswordBox)(target));
|
||||
return;
|
||||
case 4:
|
||||
this.PasswordHint = ((System.Windows.Controls.TextBlock)(target));
|
||||
return;
|
||||
switch (connectionId) {
|
||||
case 1:
|
||||
this.Login = ((Server_Dashboard.LoginWindow)(target));
|
||||
return;
|
||||
case 2:
|
||||
this.UserName = ((System.Windows.Controls.TextBox)(target));
|
||||
return;
|
||||
case 3:
|
||||
this.Password = ((System.Windows.Controls.PasswordBox)(target));
|
||||
return;
|
||||
case 4:
|
||||
this.PasswordHint = ((System.Windows.Controls.TextBlock)(target));
|
||||
return;
|
||||
}
|
||||
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
|
||||
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