changed database and implemented passwordless login
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user