Added the first part of allowing the user to reset their password.

This commit is contained in:
2021-01-08 00:00:58 -06:00
parent fb61c971e9
commit d495bfca9c
5 changed files with 68 additions and 31 deletions
+22 -7
View File
@@ -84,17 +84,18 @@ namespace SecureCore.Services
}
}
public static void SetUserSessionToken(int userId, string sessionToken, DateTime expirationDate, string userAgent, string ipAddress)
public static void SetUserSessionToken(string userName, string sessionToken, DateTime expirationDate, string userAgent, string ipAddress, bool isResetToken = false)
{
using (var connection = new SqlConnection(ConnectionString))
{
using (var command = new SqlCommand("INSERT INTO [Session]([Session Token], [Expiration Date], [User ID], [User Agent], [IP Address]) VALUES (@SessionToken, @ExpirationDate, @UserKey, @UserAgent, @IpAddress)", connection))
using (var command = new SqlCommand("InsertSessionToken", connection) { CommandType = CommandType.StoredProcedure })
{
command.Parameters.AddWithValue("SessionToken", sessionToken);
command.Parameters.AddWithValue("ExpirationDate", expirationDate);
command.Parameters.AddWithValue("UserKey", userId);
command.Parameters.AddWithValue("UserName", userName);
command.Parameters.AddWithValue("UserAgent", userAgent);
command.Parameters.AddWithValue("IpAddress", ipAddress);
command.Parameters.AddWithValue("PendingReset", isResetToken);
connection.Open();
@@ -131,10 +132,9 @@ namespace SecureCore.Services
{
using (var connection = new SqlConnection(ConnectionString))
{
using (var command = new SqlCommand("SELECT 1 AS Valid WHERE EXISTS(SELECT 1 FROM Session WHERE [Session Token] = @SessionToken)", connection))// AND[User ID] = @UserId)", connection))
using (var command = new SqlCommand("ValidateSessionToken", connection) { CommandType = CommandType.StoredProcedure })
{
command.Parameters.AddWithValue("SessionToken", sessionToken);
//command.Parameters.AddWithValue("UserId", GetUserId(userName));
connection.Open();
@@ -145,11 +145,11 @@ namespace SecureCore.Services
}
}
public static void DestorySession(string sessionToken)
public static void DestroySession(string sessionToken)
{
using (var connection = new SqlConnection(ConnectionString))
{
using (var command = new SqlCommand("DELETE FROM [Session] WHERE [Session Token] = @SessionToken", connection))
using (var command = new SqlCommand("DestroySession", connection) { CommandType = CommandType.StoredProcedure })
{
command.Parameters.AddWithValue("SessionToken", sessionToken);
@@ -159,5 +159,20 @@ namespace SecureCore.Services
}
}
}
//public static void ResetPassword(string email)
//{
// using (var connection = new SqlConnection(ConnectionString))
// {
// using (var command = new SqlCommand("DestroySession", connection) { CommandType = CommandType.StoredProcedure })
// {
// command.Parameters.AddWithValue("SessionToken", sessionToken);
// connection.Open();
// command.ExecuteNonQuery();
// }
// }
//}
}
}