public void UpdateRememberMeCookie(long selector) { SystemAdminDbContext sysDbContext = new SystemAdminDbContext(connStringAdmin); CookieAuthInfoModel authModel = (from sysAuthInfo in sysDbContext.CookieInformation where sysAuthInfo.Selector == selector select sysAuthInfo).FirstOrDefault(); //Generate unique string associated with selector --called Validator Guid gd = Guid.NewGuid(); string GuidString = Convert.ToBase64String(gd.ToByteArray()); GuidString = GuidString.Replace("=", ""); GuidString = GuidString.Replace("+", ""); //tick is also used as a salt var GuidStrWithSalt = GuidString + selector.ToString(); //generate Hash of the Validator, that can be used as a token string msgDigest = ComputeSha256Hash(GuidStrWithSalt); authModel.HashedToken = msgDigest; sysDbContext.Entry(authModel).Property(x => x.HashedToken).IsModified = true; Response.Cookies.Delete("uData"); Response.Cookies.Append("uData", GuidString, new Microsoft.AspNetCore.Http.CookieOptions { Expires = authModel.Expires }); sysDbContext.SaveChanges(); }
public void SetRememberMeCookieVariable(long selector, int userId) { try { SystemAdminDbContext sysDbContext = new SystemAdminDbContext(connStringAdmin); CookieAuthInfoModel authModel = new CookieAuthInfoModel(); //Generate unique string associated with selector --called Validator Guid gd = Guid.NewGuid(); string GuidString = Convert.ToBase64String(gd.ToByteArray()); GuidString = GuidString.Replace("=", ""); GuidString = GuidString.Replace("+", ""); //tick is also used as a salt var GuidStrWithSalt = GuidString + selector.ToString(); //generate Hash of the Validator, that can be used as a token string msgDigest = ComputeSha256Hash(GuidStrWithSalt); authModel.Selector = selector; authModel.HashedToken = msgDigest; authModel.UserId = userId; authModel.Expires = System.DateTime.Now.AddYears(2); sysDbContext.CookieInformation.Add(authModel); sysDbContext.SaveChanges(); Response.Cookies.Append("uRef", selector.ToString(), new Microsoft.AspNetCore.Http.CookieOptions { Expires = authModel.Expires }); Response.Cookies.Append("uData", GuidString, new Microsoft.AspNetCore.Http.CookieOptions { Expires = authModel.Expires }); } catch (Exception ex) { throw ex; } }