public bool ResetPassword(string Email, Control theControl)
{
MembershipUser user = null;
if (!String.IsNullOrEmpty(Email)) {
MembershipUserCollection membershipCollection = Membership.FindUsersByEmail(Email);
foreach (MembershipUser userEnum in membershipCollection) {
user = userEnum;
break;
}
}
if (user != null) {
HttpRequest request = HttpContext.Current.Request;
Assembly _assembly = Assembly.GetExecutingAssembly();
string sBody = String.Empty;
using (StreamReader oTextStream = new StreamReader(_assembly.GetManifestResourceStream("Carrotware.CMS.Core.Security.EmailForgotPassMsg.txt"))) {
sBody = oTextStream.ReadToEnd();
}
if (user.IsLockedOut && user.LastLockoutDate < DateTime.Now.AddMinutes(-45)) {
user.UnlockUser();
}
string tmpPassword = user.ResetPassword(); // set to known password
string newPassword = GenerateSimplePassword(); // create simpler password
user.ChangePassword(tmpPassword, newPassword); // set to simpler password
string strHTTPHost = String.Empty;
try { strHTTPHost = request.ServerVariables["HTTP_HOST"].ToString().Trim(); } catch { strHTTPHost = String.Empty; }
string hostName = strHTTPHost.ToLowerInvariant();
string strHTTPPrefix = "http://";
try {
strHTTPPrefix = request.ServerVariables["SERVER_PORT_SECURE"] == "1" ? "https://" : "http://";
} catch { strHTTPPrefix = "http://"; }
strHTTPHost = String.Format("{0}{1}", strHTTPPrefix, strHTTPHost).ToLowerInvariant();
sBody = sBody.Replace("{%%UserName%%}", user.UserName);
sBody = sBody.Replace("{%%Password%%}", newPassword);
sBody = sBody.Replace("{%%SiteURL%%}", strHTTPHost);
sBody = sBody.Replace("{%%Version%%}", CurrentDLLVersion);
sBody = sBody.Replace("{%%AdminFolderPath%%}", String.Format("{0}{1}", strHTTPHost, SiteData.AdminFolderPath));
if (SiteData.CurretSiteExists) {
sBody = sBody.Replace("{%%Time%%}", SiteData.CurrentSite.Now.ToString());
} else {
sBody = sBody.Replace("{%%Time%%}", DateTime.Now.ToString());
}
EmailHelper.SendMail(null, user.Email, String.Format("Reset Password {0}", hostName), sBody, false);
return true;
} else {
return false;
}
}