Started to try and organize all the authentication code.
This commit is contained in:
@@ -33,6 +33,25 @@ namespace SecureCore.Services
|
||||
}
|
||||
}
|
||||
|
||||
public static bool UserHasLoginData(string userName)
|
||||
{
|
||||
var userId = GetUserId(userName);
|
||||
|
||||
using (var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
using (var command = new SqlCommand("SELECT [Password Hash], [Salt Hash] FROM Login WHERE [User Key] = @UserId", connection))
|
||||
{
|
||||
command.Parameters.AddWithValue("UserId", userId);
|
||||
|
||||
connection.Open();
|
||||
|
||||
var reader = command.ExecuteReader();
|
||||
|
||||
return reader.HasRows;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static int GetUserId(string userName)
|
||||
{
|
||||
using (var connection = new SqlConnection(ConnectionString))
|
||||
@@ -121,5 +140,20 @@ namespace SecureCore.Services
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void DestorySession(string sessionToken)
|
||||
{
|
||||
using (var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
using (var command = new SqlCommand("DELETE FROM [Session] WHERE [Session Token] = @SessionToken", connection))
|
||||
{
|
||||
command.Parameters.AddWithValue("SessionToken", sessionToken);
|
||||
|
||||
connection.Open();
|
||||
|
||||
command.ExecuteNonQuery();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user