//Delete/Clear Session details for user public JsonResult ClearSessionDetails(string userId) { FormsAuthenticationTicket ticket = null; try { _UserSessionLogBusinessLogic = new UserSessionLogBusinessLogic(); _EncryptionModule = new EncryptionModule(); int decryptedUserId = Convert.ToInt32(_EncryptionModule.Decrypt(userId)); var result = _UserSessionLogBusinessLogic.ClearSessionDetails(decryptedUserId); return(Json(result)); } catch (Exception ex) { currentFile = this.ControllerContext.RouteData.Values["controller"].ToString(); // System.Diagnostics.StackTrace(true).GetFrame(0).GetFileName(); StackTrace st = new StackTrace(); StackFrame sf = st.GetFrame(0); methodName = sf.GetMethod().Name; ErrorLogHelper.UpdatingErrorLog(currentFile + "-" + methodName, ticket == null ? "N/A" : ticket.Name, ex); return(Json(false)); } }
/// <summary> /// Call EncryptionModule.EncryptDataBase for encryption purposes then save encrypted DB to file. /// </summary> /// <param name="fileStream">Stay at open state after method call </param> /// <param name="dataBaseToWrite"></param> private static void EncryptAndWriteDbToFile(FileStream fileStream, DataBaseInstance dataBaseToWrite) { MemoryStream streamOfEncryptedDataBase = EncryptionModule.EncryptDataBase(dataBaseToWrite); streamOfEncryptedDataBase.Position = 0; streamOfEncryptedDataBase.WriteTo(fileStream); }
//Get all user log details public JsonResult GetAllLoggedInSessions(string userId) { FormsAuthenticationTicket ticket = null; try { _UserSessionLogBusinessLogic = new UserSessionLogBusinessLogic(); _EncryptionModule = new EncryptionModule(); HttpCookie authCookie = Request.Cookies[FormsAuthentication.FormsCookieName]; int decryptedUserId = userId == "0" ? 0 : Convert.ToInt32(_EncryptionModule.Decrypt(userId)); if (authCookie != null) { ticket = FormsAuthentication.Decrypt(authCookie.Value); var userLogDetails = _UserSessionLogBusinessLogic.GetAllLoggedInSessions(decryptedUserId); var userLogDetailsEncrypted = userLogDetails .Select(ul => new { UserSessionLogId = _EncryptionModule.Encrypt(ul.UserSessionLogId.ToString()), UserId = _EncryptionModule.Encrypt(ul.UserId.ToString()), ProfilePicURL = ul.ProfilePicURL, Username = ul.Username, UserGroupName = ul.UserGroupName, UserFullName = ul.UserFullName, UserCallingName = ul.UserCallingName, IPAddress = ul.IPAddress, CountryCode = ul.CountryCode, Country = ul.Country, City = ul.City, Region = ul.Region, LoggedInTimestamp = ul.LoggedInTimestamp, LoggedOffTimestamp = ul.LoggedOffTimestamp }).ToList(); return(Json(userLogDetailsEncrypted)); } else { return(Json(null)); } } catch (Exception ex) { currentFile = this.ControllerContext.RouteData.Values["controller"].ToString(); // System.Diagnostics.StackTrace(true).GetFrame(0).GetFileName(); StackTrace st = new StackTrace(); StackFrame sf = st.GetFrame(0); methodName = sf.GetMethod().Name; ErrorLogHelper.UpdatingErrorLog(currentFile + "-" + methodName, ticket == null ? "N/A" : ticket.Name, ex); return(Json(null)); } }
//Get all system users public JsonResult GetAllUsers() { FormsAuthenticationTicket ticket = null; try { _SystemUserDirectoryBusinessLogic = new SystemUserDirectoryBusinessLogic(); HttpCookie authCookie = Request.Cookies[FormsAuthentication.FormsCookieName]; if (authCookie != null) { ticket = FormsAuthentication.Decrypt(authCookie.Value); _EncryptionModule = new EncryptionModule(); var userDetails = _SystemUserDirectoryBusinessLogic.GetAllUsers(); var userDetailsEncrypted = userDetails .Select(u => new { UserId = _EncryptionModule.Encrypt(u.UserId.ToString()), UserGroupId = u.UserGroupId, ProfilePicURL = u.ProfilePicURL, Username = u.Username, UserGroupName = u.UserGroupName, FullName = u.FullName, CallingName = u.CallingName, Email = u.Email, IsActive = u.IsActive, IsLoggedIn = u.IsLoggedIn, LastLogInTime = u.LastLogInTime, LastLogOffTime = u.LastLogOffTime, }).OrderBy(a => a.Username).ThenBy(a => a.FullName).ToList(); return(Json(userDetailsEncrypted)); } else { return(Json(null)); } } catch (Exception ex) { currentFile = this.ControllerContext.RouteData.Values["controller"].ToString(); // System.Diagnostics.StackTrace(true).GetFrame(0).GetFileName(); StackTrace st = new StackTrace(); StackFrame sf = st.GetFrame(0); methodName = sf.GetMethod().Name; ErrorLogHelper.UpdatingErrorLog(currentFile + "-" + methodName, ticket == null ? "N/A" : ticket.Name, ex); return(Json(null)); } }
private static int redirectedUserId = 0; //Variable to get when user Id is redirected from another page public ActionResult Index(string userId = null) { FormsAuthenticationTicket ticket = null; try { // string LoginUserType = System.Web.HttpContext.Current.Session["LoginUserType"].ToString(); _UserDetailsBusinessLogic = new UserDetailsBusinessLogic(); _EncryptionModule = new EncryptionModule(); HttpCookie authCookie = System.Web.HttpContext.Current.Request.Cookies[FormsAuthentication.FormsCookieName]; if (authCookie != null) { ticket = FormsAuthentication.Decrypt(authCookie.Value); ViewBag.Username = ticket.Name; ViewBag.UserType = _UserDetailsBusinessLogic.GetUserType(ticket.Name).ToLower().Trim(); ViewBag.RedirectedUserId = userId != null?_EncryptionModule.Decrypt(userId.ToString()) : "0"; redirectedUserId = userId != null?Convert.ToInt32(_EncryptionModule.Decrypt(userId.ToString())) : 0; //Initialize AWS Configurations => Required for image uploads InitAWSS3Configurations(); return(View()); } else { this.HttpContext.Session["ErrorMsg"] = "LoginErr"; return(RedirectToAction("Index", "Login")); } } catch (Exception ex) { currentFile = this.ControllerContext.RouteData.Values["controller"].ToString(); // System.Diagnostics.StackTrace(true).GetFrame(0).GetFileName(); StackTrace st = new StackTrace(); StackFrame sf = st.GetFrame(0); methodName = sf.GetMethod().Name; ErrorLogHelper.UpdatingErrorLog(currentFile + "-" + methodName, ticket == null ? "N/A" : ticket.Name, ex); this.HttpContext.Session["ErrorMsg"] = "PageLoadError"; return(RedirectToAction("Index", "LoginError")); } }
static void Main(string[] args) { // Connect to device at specific port var module = EncryptionModule.Connect("COM8"); // Set password for VMPC module.SetPassword("test"); // Initialize VMPC module.InitializeCipher(); // Encrypt sequence var encrypted = module.EncryptSequence("test"); Console.WriteLine(encrypted.GetDataString()); // Reinitialize cipher module.InitializeCipher(); // Decrypt sequence var decrypted = module.EncryptSequence(encrypted); Console.WriteLine(decrypted.GetDataString()); // Config examples Console.WriteLine("=== Config ==="); // Stream chunk size module.SetStreamChunkSize(4); Console.WriteLine($"StreamChunkSize: {module.GetStreamChunkSize()}"); //module.BeginStreamEncryption(data => { /**/ }); /*while (true) * { * module.SendStreamData(Encoding.ASCII.GetBytes("test")); * // Thread.Sleep(50); * }*/ }