コード例 #1
0
 private static void Login(UserToken token, String userName)
 {
     if (token == null)
     {
         SiteSecurity.LogFailure(userName);
     }
     else
     {
         SiteSecurity.LogSuccess(token.Name);
         GenericIdentity  identity  = new GenericIdentity(token.Name, "Custom");
         GenericPrincipal principal = new GenericPrincipal(identity, new string[] { token.Role });
         HttpContext.Current.User = principal;
         System.Threading.Thread.CurrentPrincipal = principal;
     }
 }
コード例 #2
0
        /// <summary>
        /// This function takes a password, the  challenge and the userName to
        /// make an super challenge like on the client side.
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="clientHash"></param>
        /// <param name="challenge"></param>
        /// <returns>user as UserToken.</returns>
        public static UserToken Login(string userName, string clientHash, string challenge)
        {
            ILoggingDataService loggingService = LoggingDataServiceFactory.GetService(SiteConfig.GetLogPathFromCurrentContext());

            UserToken token = null;

            /*
             *          SiteSecurityConfig ssc = GetSecurity();
             *          foreach (User user in ssc.Users)
             *          {
             *  if (user.Active && user.Name.Equals(userName, StringComparison.InvariantCultureIgnoreCase))
             *                  {
             *                          if (DoSuperChallenge(challenge, user.Password, userName, clientHash))
             *                          {
             *                                  token = user.ToToken();
             *                                  break;
             *                          }
             *                  }
             *          }
             */
            User user = GetUser(userName);

            if (user != null && user.Active && DoSuperChallenge(challenge, user.Password, userName, clientHash))
            {
                token = user.ToToken();
            }

            if (token == null)
            {
                SiteSecurity.LogFailure(userName);
            }
            else
            {
                SiteSecurity.LogSuccess(token.Name);
                GenericIdentity  identity  = new GenericIdentity(token.Name, "Custom");
                GenericPrincipal principal = new GenericPrincipal(identity, new string[] { token.Role });
                HttpContext.Current.User = principal;
                System.Threading.Thread.CurrentPrincipal = principal;
            }

            return(token);
        }