public string AddSession() { string sSession = GetRandomString(RANDOM_LENGTH, RANDOM_CHARACTERSUSED.ToCharArray()); //Vi kan ikke ha den samme session navnet 2 ganger... (kjør loop til den er unik) while (SessionExists(sSession)) { sSession = GetRandomString(RANDOM_LENGTH, RANDOM_CHARACTERSUSED.ToCharArray()); } SessionStruct structSession = new SessionStruct(); structSession.sLastUsed = DateTime.Now; structSession.sID = sSession; structSession.bLoggedIn = false; structSession.UserID = -1; //Store in database LiteCollection <SessionStruct> aDBValues = m_db.GetCollection <SessionStruct>("session"); aDBValues.EnsureIndex(x => x.sID); aDBValues.Insert(structSession); //Now add a TempID for verify the HTTP cookie for it GenerateTempIDInSession(sSession); return(sSession); }
//===================================== //Public functions here public bool SessionExists(string sSession) { LiteCollection <SessionStruct> aDBValues = m_db.GetCollection <SessionStruct>("session"); SessionStruct results = aDBValues.FindOne(x => x.sID == sSession); if (results != null) { return(true); } return(false); }
//Removes a session public bool RemoveSession(string sSession) { //Find our session and remove it1 LiteCollection <SessionStruct> aDBValues = m_db.GetCollection <SessionStruct>("session"); SessionStruct results = aDBValues.FindOne(x => x.sID == sSession); if (results == null) { return(false); } aDBValues.Delete(results.Id); return(true); }
public bool SessionLoggedIn(string sSession, string sUser) { LiteCollection <SessionStruct> aDBValues = m_db.GetCollection <SessionStruct>("session"); SessionStruct results = aDBValues.FindOne(x => x.sID == sSession); if (results == null) { return(false); } else { //Check if the session is expired, remove session if so if (SessionExpired(results.sLastUsed)) { RemoveSession(sSession); return(false); } //Special case for Websites, since the AuthID is not a cookie, we cannot receive it... if (sUser == "[WEBBASEDAUTH, NOT USER]") { return(results.bLoggedIn); } //Here we compare the username against the session, false if no good... string sUsername = GetTemporaryVariable(sSession, "Username"); //if (((SessionStruct)aSessions[nID]).sDisplayname == sUser) //Temp hack if (sUsername == sUser) { return(results.bLoggedIn); } else { return(false); } } }
public void SetLogin(string sSession, bool bLoginState, string sUsername) { LiteCollection <SessionStruct> aDBValues = m_db.GetCollection <SessionStruct>("session"); SessionStruct results = aDBValues.FindOne(x => x.sID == sSession); if (results == null) { return; } //Check if the session is expired, remove session if so if (SessionExpired(results.sLastUsed)) { RemoveSession(sSession); return; } //Set the state of the session results.sLastUsed = DateTime.Now; results.bLoggedIn = bLoginState; results.UserID = m_Users.GetUserID(sUsername); aDBValues.Update(results); }