public IdSession Login(LoginPassword loginPassword) { string getUser = $"select * from Users where email = '{loginPassword.Email}'"; User loginUser = dbr.GetFirstOrDefault <User>(getUser); if (loginUser == null) { return(null); } string getPassword = $"select password from Passwords where ownerId = {loginUser.Id}"; string dbSavedPasswordHash = dbr.GetFirstOrDefault <string>(getPassword); if (String.IsNullOrEmpty(dbSavedPasswordHash)) { return(null); } if (sHelper.CheckIfPasswordMatches(dbSavedPasswordHash, loginPassword.Password, 20)) { Guid sessionGuid = sHelper.CreateLoginSession(loginUser.Id); IdSession sessionDetails = new IdSession { OwnerId = loginUser.Id, SessionGuid = sessionGuid }; return(sessionDetails); } else { return(null); } }
private bool ValdidateSessionContext(HttpContext httpContext) { string contextUser = httpContext.Request.Headers["UserId"]; string contextSessionGuid = httpContext.Request.Headers["SessionGuid"]; if (string.IsNullOrEmpty(contextSessionGuid) || string.IsNullOrEmpty(contextUser)) { return(false); } IdSession idSession = new IdSession { OwnerId = Convert.ToInt32(contextUser), SessionGuid = new Guid(contextSessionGuid) }; return(GetCurrentSessionState(idSession)); }
public bool GetCurrentSessionState(IdSession currentSessionInfo) { string checkSession = $"select * from Sessions where OwnerId = {currentSessionInfo.OwnerId}"; Session existingSession = dbr.GetFirstOrDefault <Session>(checkSession); if (existingSession == null) { return(false); } else if (existingSession.ValidTo < DateTime.UtcNow || existingSession.SessionGuid != currentSessionInfo.SessionGuid) { KillSessionForUserId(currentSessionInfo.OwnerId); return(false); } else { return(true); } }