{"id":70,"date":"2019-09-15T05:45:47","date_gmt":"2019-09-15T05:45:47","guid":{"rendered":"http:\/\/sumitjangid.com\/?p=70"},"modified":"2019-09-15T05:45:47","modified_gmt":"2019-09-15T05:45:47","slug":"manually-logging-user-with-role","status":"publish","type":"post","link":"http:\/\/sumitjangid.com\/index.php\/2019\/09\/15\/manually-logging-user-with-role\/","title":{"rendered":"Manually Logging User with Role"},"content":{"rendered":"\n<p>To logging a user with a custom role, you have to create an authentication cookies, only after user has been authenticated (Username and password has been verified).<\/p>\n\n\n\n<blockquote class=\"wp-block-quote\"><p> FormsAuthenticationTicket\u00a0Class <br>Namespace: <a href=\"https:\/\/docs.microsoft.com\/en-us\/dotnet\/api\/system.web.security?view=netframework-4.8\">System.Web.Security<\/a><br>Assembly: System.Web.dll <br><br><em>Constructor:  public FormsAuthenticationTicket (int version, string name, DateTime issueDate, DateTime expiration, bool isPersistent, string userData, string cookiePath); <br><\/em><\/p><\/blockquote>\n\n\n\n<p><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>if (user_authenticated == true)\n  {\n     FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, TempData.Peek(\"userid\").ToString(), DateTime.Now, DateTime.Now.AddMinutes(15)\n                        , false,Session[\"role\"].ToString(), FormsAuthentication.FormsCookiePath);\n                new Helpers().LogActivity(User.Identity.Name.ToString(), \"LoginAttempt\", \"Success\");\n                string hash = FormsAuthentication.Encrypt(ticket);\n                HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, hash);\n                Response.Cookies.Add(cookie);<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>To logging a user with a custom role, you have to create an authentication cookies, only after user has been authenticated (Username and password has been verified). FormsAuthenticationTicket\u00a0Class Namespace: System.Web.SecurityAssembly: System.Web.dll Constructor: public FormsAuthenticationTicket (int&hellip; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3,5,2],"tags":[],"_links":{"self":[{"href":"http:\/\/sumitjangid.com\/index.php\/wp-json\/wp\/v2\/posts\/70"}],"collection":[{"href":"http:\/\/sumitjangid.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/sumitjangid.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/sumitjangid.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/sumitjangid.com\/index.php\/wp-json\/wp\/v2\/comments?post=70"}],"version-history":[{"count":1,"href":"http:\/\/sumitjangid.com\/index.php\/wp-json\/wp\/v2\/posts\/70\/revisions"}],"predecessor-version":[{"id":71,"href":"http:\/\/sumitjangid.com\/index.php\/wp-json\/wp\/v2\/posts\/70\/revisions\/71"}],"wp:attachment":[{"href":"http:\/\/sumitjangid.com\/index.php\/wp-json\/wp\/v2\/media?parent=70"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/sumitjangid.com\/index.php\/wp-json\/wp\/v2\/categories?post=70"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/sumitjangid.com\/index.php\/wp-json\/wp\/v2\/tags?post=70"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}