public static string GetFormsAuthenticationTicket()
 {
     using (var pm = new ProviderManager())
     {
         ProviderBase wsProvider = pm.Providers["WebServiceUserManager"];
         if (wsProvider != null)
         {
             WebServiceManager wsm = wsProvider.CreateUserManager() as WebServiceManager;
             wsm.ReAuthenticate();
             string ticket = wsm.GetFormsAuthenticationTicket();
             return ticket;
         }
     }
     return null;
 }
        /// <summary>
        /// Login
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public static IPrincipal Login(string userName, string password)
        {
            using (var pm = new ProviderManager())
            {
                IUserManager um = pm.DefaultProvider.CreateUserManager();

                bool authenticate = um.Authenticate(SystemConfiguration.ApplicationName, userName, password);
                if (authenticate)
                {
                    IIdentity identity = new GenericIdentity(userName, pm.DefaultProvider.Name);
                    Debug.Assert(identity.IsAuthenticated);

                    string[] roles = um.GetRoles(SystemConfiguration.ApplicationName, userName);
                    IPrincipal principal = new GenericPrincipal(identity, roles);

                    SystemConfiguration.UserName = userName;
                    SystemConfiguration.Roles = roles;
                    SystemConfiguration.Password = password;
                    // Todo: Change to correct OrgId and ClientId
                    SystemConfiguration.ClientId = 0;
                    SystemConfiguration.OrgId = 0;

                    return principal;
                    //AppDomain.CurrentDomain.SetThreadPrincipal(principal);

                    //IToken token = SecurityCacheFactory.GetSecurityCacheProvider().SaveIdentity(identity);
                    //IIdentity t1 = SecurityCacheFactory.GetSecurityCacheProvider().GetIdentity(new GuidToken(new Guid("9958226e-0491-4c50-b189-affc0eb0ca81")));
                }
                else
                {
                    SystemConfiguration.UserName = null;
                    SystemConfiguration.Roles = new string[0];
                    SystemConfiguration.Password = string.Empty;
                }
                return null;
            }
        }
        private void btnOk_Click(object sender, EventArgs e)
        {
            m_success = false;

            string password0 = m_PasswordBox0.Text;
            string password = m_PasswordBox.Text;
            string password2 = m_PasswordBox2.Text;

            if (password0 == String.Empty)
            {
                m_ErrorProvider.SetError(m_PasswordBox0, "�����������");
                return;
            }
            else
            {
                m_ErrorProvider.SetError(m_PasswordBox0, String.Empty);
            }
            if (password == String.Empty)
            {
                m_ErrorProvider.SetError(m_PasswordBox, "������������");
                return;
            }
            else
            {
                m_ErrorProvider.SetError(m_PasswordBox, String.Empty);
            }
            if (password.Length < 6)
            {
                m_ErrorProvider.SetError(m_PasswordBox, "���볤��С��6λ");
                return;
            }
            else
            {
                m_ErrorProvider.SetError(m_PasswordBox, String.Empty);
            }
            if (password != password2)
            {
                m_ErrorProvider.SetError(m_PasswordBox2, "��������������벻ƥ��");
                return;
            }
            else
            {
                m_ErrorProvider.SetError(m_PasswordBox2, String.Empty);
            }

            try
            {
                using (var pm = new ProviderManager())
                {
                    IUserManager userManager = pm.DefaultProvider.CreateUserManager();
                    WebServiceManager webServiceManager = userManager as WebServiceManager;
                    if (webServiceManager != null)
                    {
                        webServiceManager.ReAuthenticate();
                    }

                    bool res = pm.DefaultProvider.CreatePasswordManager().ChangePasswordWithOldPassword(
                            SystemConfiguration.ApplicationName, SystemConfiguration.UserName,
                            password0, password);
                    if (res)
                    {
                        m_success = res;
                        MessageForm.ShowInfo("�޸�����ɹ�");
                    }
                    else
                    {
                        MessageForm.ShowInfo("�޸�����ʧ��");
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionProcess.ProcessWithResume(ex);
                MessageForm.ShowError("�޸�����ʧ��");
            }

            if (m_success)
            {
                this.Close();
            }
        }