/// <summary>
        /// Tries to log in with the corresponding method of  
        /// <c>UserService</c>, and if successful, inserts in the
        /// session the necessary objects for an authenticated user.
        /// </summary>
        /// <param name="context">Http Context includes request, response, etc.</param>
        /// <param name="loginName">Username</param>
        /// <param name="password">User Password</param>
        /// <param name="passwordIsEncrypted">Password is either encrypted or 
        /// in clear text</param>
        /// <param name="rememberMyPassword">Remember password to the next 
        /// logins</param>
        /// <exception cref="IncorrectPasswordException"/>
        /// <exception cref="InstanceNotFoundException"/>        
        private static LoginResult DoLogin(HttpContext context,
             String loginName, String password, Boolean passwordIsEncrypted,
             Boolean rememberMyPassword)
        {

            LoginResult loginResult =
                userService.Login(loginName, password,
                    passwordIsEncrypted);

            /* Insert necessary objects in the session. */

            UserSession userSession = new UserSession();
            userSession.UserProfileId = loginResult.UserProfileId;
            userSession.FirstName = loginResult.FirstName;

            String language = GetLanguageFromBrowserPreferences();
            String country = GetCountryFromBrowserPreferences();

            Locale locale = new Locale(language, country);

            UpdateSessionForAuthenticatedUser(context, userSession, locale);

            return loginResult;

        }
 /// <summary>
 /// Updates the session values for an previously authenticated user
 /// </summary>
 /// <param name="context">Http Context includes request, response, etc.</param>
 /// <param name="userSession">The user data stored in session.</param>
 /// <param name="locale">The locale info.</param>
 private static void UpdateSessionForAuthenticatedUser(
     HttpContext context, UserSession userSession, Locale locale)
 {
     /* Insert objects in session. */
     context.Session.Add(USER_SESSION_ATTRIBUTE, userSession);
     context.Session.Add(LOCALE_SESSION_ATTRIBUTE, locale);
 }
        /// <summary>
        /// Registers the user.
        /// </summary>
        /// <param name="context">Http Context includes request, response, etc.</param>
        /// <param name="loginName">Username</param>
        /// <param name="clearPassword">Password in clear text</param>
        /// <param name="userProfileDetails">The user profile details.</param>
        /// <exception cref="DuplicateInstanceException"/>
        public static void RegisterUser(HttpContext context, 
            String loginName, String clearPassword,
            UserProfileDetails userProfileDetails)
        {
            
            /* Register user. */
            long usrId = userService.RegisterUser(loginName, clearPassword,
                userProfileDetails);

            /* Insert necessary objects in the session. */
            UserSession userSession = new UserSession();
            userSession.UserProfileId = usrId;
            userSession.FirstName = userProfileDetails.FirstName;

            String language = GetLanguageFromBrowserPreferences();
            String country = GetCountryFromBrowserPreferences();

           Locale locale = new Locale(language,country);

            UpdateSessionForAuthenticatedUser(context, userSession, locale);

            FormsAuthentication.SetAuthCookie(loginName, false);
        }