Esempio n. 1
0
        public string ResetUserPassword(string appName, string userName, bool MappedApplication)
        {
            string oldApp      = Membership.ApplicationName;
            string newPassword = string.Empty;

            try
            {
                if (MappedApplication)
                {
                    Membership.ApplicationName = GetMapping(appName);
                }
                else
                {
                    Membership.ApplicationName = appName;
                }

                MembershipUser user = Membership.GetUser(userName);
                if (user == null)
                {
                    ULS.LogError("SQLMembershipWS", "No user found for " + appName + ":" + userName, "SQLMembershipWS");
                    throw new Exception("User (" + userName + ") Could Not Be Found");
                }

                newPassword = user.ResetPassword();
            }
            finally
            {
                Membership.ApplicationName = oldApp;
            }
            return(newPassword);
        }
Esempio n. 2
0
        /// <summary>
        /// Get the connection string for the provider.
        /// </summary>
        /// <param name="providerName">The name of the provider.</param>
        /// <returns>The connection string.</returns>
        private string GetConnectionString(string providerName)
        {
            string connStr = string.Empty;

            try
            {
                RoleManagerSection configSection = (RoleManagerSection)HttpContext.Current.GetSection("system.web/roleManager");

                ProviderSettings providerItem = configSection.Providers[providerName];
                if (providerItem != null)
                {
                    string connStrName = providerItem.Parameters["connectionStringName"];
                    if (!string.IsNullOrEmpty(connStrName))
                    {
                        connStr = WebConfigurationManager.ConnectionStrings[connStrName].ConnectionString;
                    }
                }
            }
            catch (Exception e)
            {
                ULS.LogError("SqlSiteRoleProvider.GetConnectionString", "No Connection String Retrieved for provider name: " + providerName + "\n" + e.ToString(), "RoleProvider");
                throw new ProviderException(e.ToString());
            }

            return(connStr);
        }
Esempio n. 3
0
        /// <summary>
        /// Delete a user from the membership directory
        /// </summary>
        /// <param name="UserName">The user name of the user to delete</param>
        private static void DeleteUser(string UserName)
        {
            bool bDeleted = false;

            bDeleted = Membership.DeleteUser(UserName, true);
            if (bDeleted == false)
            {
                ULS.LogError("DeleteUser", "The user could not be deleted: " + UserName, "SQLMembershipWS");
                throw new Exception("The user could not be deleted.");
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Create a new user in the membership directory
        /// </summary>
        /// <param name="login">The user name for the new user.</param>
        /// <param name="password">The password for the new user.</param>
        /// <param name="email">The e-mail address for the new user.</param>
        /// <param name="passwordQuestion">The password-question value for the membership user.</param>
        /// <param name="passwordAnswer">The password-answer value for the membership user.</param>
        private static void CreateUser(string login, string password, string email, string passwordQuestion, string passwordAnswer)
        {
            MembershipCreateStatus userStatus = new MembershipCreateStatus();

            // Create the user in the SQL membership database
            Membership.CreateUser(login, password, email, passwordQuestion, passwordAnswer, true, out userStatus);

            // Check the Status
            if (userStatus != MembershipCreateStatus.Success)
            {
                ULS.LogError("CreateUser", "User " + login + " failed with status " + userStatus.ToString(), "SQLMembershipWS");
                throw new Exception("User " + login + " failed with status " + userStatus.ToString());
            }
        }
 /// <summary>
 /// When this feature is deactivated, it removes the connection string,
 /// membership provider, and role provider information from the web.config
 /// for the web application.  The People picker setting for the web app
 /// is left as is because we don't know what the correct state would be.
 /// </summary>
 public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
 {
     try
     {
         SPWebApplication webApp = properties.Feature.Parent as SPWebApplication;
         if (webApp != null)
         {
             WebConfigManager.WebConfigManager.RemoveConfiguration(webApp, _MODIFICATIONOWNER);
             ULS.LogMessage("SecProviderFeatureReceiver.FeatureDeactivating", "Feature Deactivated on web app: " + webApp.Name, "Membership", TraceProvider.TraceSeverity.InformationEvent);
         }
         else
         {
             ULS.LogMessage("SecProviderFeatureReceiver.FeatureDeactivating", "Not able to retrieve SPWebApplication", "Membership", TraceProvider.TraceSeverity.CriticalEvent);
         }
     }
     catch (Exception ex)
     {
         ULS.LogError("SecProviderFeatureReceiver.FeatureDeactivating", ex);
         throw ex;
     }
 }
Esempio n. 6
0
        /// <summary>
        /// changes the user's password
        /// </summary>
        /// <param name="UserName">user name</param>
        /// <param name="OldPassword">old password</param>
        /// <param name="NewPassword">new password</param>
        private static void ChangePassword(string UserName, string OldPassword, string NewPassword)
        {
            MembershipProvider defaultProvider;
            bool bChanged = false;

            defaultProvider = Membership.Provider;

            if (defaultProvider.EnablePasswordReset)
            {
                bChanged = defaultProvider.ChangePassword(UserName, OldPassword, NewPassword);
                if (bChanged == false)
                {
                    ULS.LogError("ChangePassword", "Password Not Changed: " + UserName, "SQLMembershipWS");
                    throw new Exception("This password could not be changed.");
                }
            }
            else
            {
                // This provider is not configured to let users change their passwords
                throw new Exception("You do not have permissions to change your password.");
            }
        }
 /// <summary>
 /// When this feature is activated it adds connection string, membership
 /// provider, and role provider entries into the web.config for the
 /// web application.
 ///
 /// It also sets the web application's people picker to only search within
 /// the current site collection
 /// </summary>
 public override void FeatureActivated(SPFeatureReceiverProperties properties)
 {
     try
     {
         SPWebApplication webApp = properties.Feature.Parent as SPWebApplication;
         if (webApp != null)
         {
             WebConfigManager.WebConfigManager.AddConfigModifications(webApp, _MODIFICATIONOWNER, GetWebConfigMods());
             webApp.PeoplePickerSettings.OnlySearchWithinSiteCollection = true;
             ULS.LogMessage("SecProviderFeatureReceiver.FeatureActivated", "Feature Activated on web app: " + webApp.Name, "Membership", TraceProvider.TraceSeverity.InformationEvent);
         }
         else
         {
             ULS.LogMessage("SecProviderFeatureReceiver.FeatureActivated", "Not able to retrieve SPWebApplication", "Membership", TraceProvider.TraceSeverity.CriticalEvent);
         }
     }
     catch (Exception ex)
     {
         ULS.LogError("SecProviderFeatureReceiver.FeatureActivated", ex);
         throw ex;
     }
 }
Esempio n. 8
0
        public string FindUser(string appName, string userName, bool MappedApplication)
        {
            StringBuilder userXml = new StringBuilder();
            string        oldApp  = Membership.ApplicationName;

            try
            {
                if (MappedApplication)
                {
                    Membership.ApplicationName = GetMapping(appName);
                }
                else
                {
                    Membership.ApplicationName = appName;
                }
                MembershipUser user = Membership.GetUser(userName);
                if (user == null)
                {
                    ULS.LogError("FindUser", "No user found for " + appName + ":" + userName, "SQLMembershipWS");
                    throw new Exception("User (" + userName + ") not found");
                }

                userXml.Append("<user>");
                userXml.Append("<login>");
                userXml.Append(user.UserName);
                userXml.Append("</login>");
                userXml.Append("<email>");
                userXml.Append(user.Email);
                userXml.Append("</email>");
                userXml.Append("</user>");
            }
            finally
            {
                Membership.ApplicationName = oldApp;
            }
            return(userXml.ToString());
        }
Esempio n. 9
0
        static void Main(string[] args)
        {
            try
            {
                string host                = ConfigurationManager.AppSettings.Get("popHost");
                int    port                = Convert.ToInt32(ConfigurationManager.AppSettings.Get("popPort"));
                bool   useSSL              = Convert.ToBoolean(ConfigurationManager.AppSettings.Get("useSSL"));
                string username            = ConfigurationManager.AppSettings.Get("popUser");
                string password            = ConfigurationManager.AppSettings.Get("popPassword");
                string dropPath            = ConfigurationManager.AppSettings.Get("dropFolderPath");
                bool   traceToConsole      = Convert.ToBoolean(ConfigurationManager.AppSettings.Get("traceToConsole"));
                bool   deleteAfterRetrieve = Convert.ToBoolean(ConfigurationManager.AppSettings.Get("deleteAfterRetrieve"));

                TraceProvider.RegisterTraceProvider();

                using (Pop3Client popClient = new Pop3Client(host, port, useSSL, username, password))
                {
                    if (traceToConsole)
                    {
                        popClient.Trace += new Action <string>(Console.WriteLine);
                    }

                    //connects to Pop3 Server, Executes POP3 USER and PASS
                    popClient.Authenticate();
                    popClient.Stat();

                    System.Net.Mail.SmtpClient smtpClient = new System.Net.Mail.SmtpClient();
                    smtpClient.DeliveryMethod          = System.Net.Mail.SmtpDeliveryMethod.SpecifiedPickupDirectory;
                    smtpClient.PickupDirectoryLocation = dropPath;
                    StringBuilder traceMessage = new StringBuilder("Messages To Retrieve: " + popClient.List().Count);
                    Console.WriteLine(traceMessage.ToString());
                    ULS.LogMessage("Pop Client", traceMessage.ToString(), "E-Mail", TraceProvider.TraceSeverity.InformationEvent);
                    foreach (Pop3ListItem item in popClient.List())
                    {
                        using (MailMessageEx popMessage = popClient.RetrMailMessageEx(item))
                        {
                            using (System.Net.Mail.MailMessage smtpMessage = new System.Net.Mail.MailMessage())
                            {
                                if (traceToConsole)
                                {
                                    foreach (System.Net.Mail.MailAddress toAddress in popMessage.To)
                                    {
                                        Console.WriteLine("To:  " + toAddress.Address);
                                    }
                                    Console.WriteLine("From: " + popMessage.From.Address);
                                    Console.WriteLine("Subject: " + popMessage.Subject);
                                    Console.WriteLine("Attachments: " + popMessage.Attachments.Count);
                                    foreach (System.Net.Mail.Attachment attachment in popMessage.Attachments)
                                    {
                                        Console.WriteLine("Attachment: " + attachment.Name);
                                    }
                                    Console.Write("Body: " + popMessage.Body + "\n");
                                }

                                smtpMessage.From            = popMessage.From;
                                smtpMessage.Subject         = popMessage.Subject;
                                smtpMessage.SubjectEncoding = popMessage.SubjectEncoding;
                                smtpMessage.Body            = popMessage.Body;
                                smtpMessage.BodyEncoding    = popMessage.BodyEncoding;
                                smtpMessage.Sender          = popMessage.Sender;

                                traceMessage = new StringBuilder("Message Processed:<br/>\n");

                                foreach (System.Net.Mail.MailAddress toAddress in popMessage.To)
                                {
                                    traceMessage.Append("To: " + toAddress + "<br/>\n");
                                    smtpMessage.To.Add(toAddress);
                                }
                                foreach (System.Net.Mail.MailAddress ccAddress in popMessage.CC)
                                {
                                    traceMessage.Append("CC: " + ccAddress + "<br/>\n");
                                    smtpMessage.CC.Add(ccAddress);
                                }
                                traceMessage.Append("From: " + popMessage.From.Address + "<br/>\n");
                                traceMessage.Append("Subject: " + popMessage.Subject + "<br/>\n");

                                foreach (System.Net.Mail.Attachment attachment in popMessage.Attachments)
                                {
                                    smtpMessage.Attachments.Add(attachment);
                                    traceMessage.Append("Attachment: " + attachment.Name + "<br/>\n");
                                }

                                smtpMessage.IsBodyHtml = popMessage.IsBodyHtml;

                                foreach (string key in popMessage.Headers.AllKeys)
                                {
                                    smtpMessage.Headers.Add(key, popMessage.Headers[key]);
                                }

                                ULS.LogMessage("Pop Client", traceMessage.ToString(), "E-Mail", TraceProvider.TraceSeverity.InformationEvent);

                                smtpClient.Send(smtpMessage);

                                if (deleteAfterRetrieve)
                                {
                                    popClient.Dele(item);
                                }
                            }
                        }
                    }
                    popClient.Noop();
                    if (!deleteAfterRetrieve)
                    {
                        popClient.Rset();
                    }
                    popClient.Quit();
                }
            }
            catch (Exception ex)
            {
                ULS.LogError("Pop Client", ex.ToString(), "E-Mail");
            }
            TraceProvider.UnregisterTraceProvider();
        }