kentico_jurajo
-
8/28/2008 5:54:46 AM
RE:How to programmatically log in a user
Hi,
I know that you have received a reply from my colleague via e-mail. I hope it helped. I am posting here his answer also here for the case if someone will need it also.
Here is the answer:
CMS.SiteProvider.UserInfo uI = CMS.SiteProvider.UserInfoProvider.AuthenticateUser("USERNAME", "PASSWORD", CMS.CMSHelper.CMSContext.CurrentSite.SiteName);
if (uI != null) { if (Membership.ValidateUser("USERNAME", "PASSWORD")) { FormsAuthentication.SetAuthCookie("USERNAME", false); CMS.GlobalHelper.RequestStockHelper.Remove("CurrentUser"); CMS.GlobalHelper.RequestStockHelper.Add("CurrentUser", new CMS.CMSHelper.CurrentUserInfo(uI)); } }
If you know user's userID, you can create your own query to get user name and password from database and use them in AuthenticateUser method. You can see our API documentation for more information about methods I mentioned in the example: http://devnet.kentico.com/Documentation.aspx
Best Regards, Juraj Ondrus
|