/// <summary> /// Request Password method. /// </summary> /// <returns></returns> public ReturnValue RequestPassword(string userName) { ReturnValue returnValue = new ReturnValue(); try { try { ApplicationSettings.NewSession(); SrvPmsPassGen newPassword = new SrvPmsPassGen(); string Password; string error; string warning; SrvPassword srvPassword = new SrvPassword(); UserInformation.Instance.DbLogon = userName; srvPassword.Load(userName); //srvPassword.OriginalPassword = srvPassword.UserPassword; if (srvPassword.UserName == null) { throw new Exception("Not a valid user"); } //Make sure the password we have generated passes validation do { Password = newPassword.GenStrongPass(10); srvPassword.NewPassword = Password; } while (srvPassword.ValidateNewPassword(out error, out warning) == false); srvPassword.RepeatPassword = Password; srvPassword.RequireChange = false; srvPassword.ResetUserLoggedIn = true; try { srvPassword.Save(); } catch (Exception ex) { returnValue.Success = false; returnValue.Message = ex.Message; } if (error == string.Empty) { returnValue.Success = true; } else { returnValue.Success = false; returnValue.Message = error; } //Send E-mail; //create the mail message MailMessage mail = new MailMessage(); //set the addresses mail.From = new MailAddress(userName); mail.To.Add(userName); //set the content mail.Subject = "Fee Earner Desktop - New Password"; string emailBody = "<p style='font-family:arial;font-size:8pt'><b>Your new password for the Fee Earner Desktop is - </b> " + Password + " </p><br/>"; emailBody += "<br/><br/><b>Please do not reply to this e-mail.</b>"; emailBody += "</table>"; mail.Body = emailBody; mail.IsBodyHtml = true; //send the message SmtpClient smtp = new SmtpClient(); smtp.Host = ConfigurationManager.AppSettings["SMTPHost"].ToString(); smtp.Port = int.Parse(ConfigurationManager.AppSettings["SMTPPort"].ToString()); if (ConfigurationManager.AppSettings["SMTPUserName"].ToString() != string.Empty && ConfigurationManager.AppSettings["SMTPPassword"].ToString() != string.Empty) { System.Net.NetworkCredential credentials = new System.Net.NetworkCredential(ConfigurationManager.AppSettings["SMTPUserName"].ToString(), ConfigurationManager.AppSettings["SMTPPassword"].ToString()); smtp.Credentials = credentials; smtp.UseDefaultCredentials = false; } else { smtp.UseDefaultCredentials = true; } if (ConfigurationManager.AppSettings["IISVersion"].ToString() == "7") { smtp.DeliveryMethod = SmtpDeliveryMethod.Network; } else { smtp.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis; } smtp.Send(mail); } finally { ApplicationSettings.RemoveSession(); } } catch (System.Data.SqlClient.SqlException) { returnValue.Success = false; returnValue.Message = Functions.SQLErrorMessage; } catch (Exception ex) { returnValue.Success = false; returnValue.Message = ex.Message; } return(returnValue); }
/// <summary> /// Request Password method. /// </summary> /// <returns></returns> public ReturnValue RequestPassword(string userName) { ReturnValue returnValue = new ReturnValue(); try { try { ApplicationSettings.NewSession(); SrvPmsPassGen newPassword = new SrvPmsPassGen(); string Password; string error; string warning; SrvPassword srvPassword = new SrvPassword(); UserInformation.Instance.DbLogon= userName; srvPassword.Load(userName); //srvPassword.OriginalPassword = srvPassword.UserPassword; if (srvPassword.UserName==null) throw new Exception("Not a valid user"); //Make sure the password we have generated passes validation do { Password = newPassword.GenStrongPass(10); srvPassword.NewPassword = Password; } while (srvPassword.ValidateNewPassword(out error, out warning) == false); srvPassword.RepeatPassword = Password; srvPassword.RequireChange = false; srvPassword.ResetUserLoggedIn = true; try { srvPassword.Save(); } catch(Exception ex) { returnValue.Success = false; returnValue.Message = ex.Message; } if (error == string.Empty) { returnValue.Success = true; } else { returnValue.Success = false; returnValue.Message = error; } //Send E-mail; //create the mail message MailMessage mail = new MailMessage(); //set the addresses mail.From = new MailAddress(userName); mail.To.Add(userName); //set the content mail.Subject = "Fee Earner Desktop - New Password"; string emailBody = "<p style='font-family:arial;font-size:8pt'><b>Your new password for the Fee Earner Desktop is - </b> " + Password + " </p><br/>"; emailBody += "<br/><br/><b>Please do not reply to this e-mail.</b>"; emailBody += "</table>"; mail.Body = emailBody; mail.IsBodyHtml = true; //send the message SmtpClient smtp = new SmtpClient(); smtp.Host = ConfigurationManager.AppSettings["SMTPHost"].ToString(); smtp.Port = int.Parse(ConfigurationManager.AppSettings["SMTPPort"].ToString()); if (ConfigurationManager.AppSettings["SMTPUserName"].ToString() != string.Empty && ConfigurationManager.AppSettings["SMTPPassword"].ToString() != string.Empty) { System.Net.NetworkCredential credentials = new System.Net.NetworkCredential(ConfigurationManager.AppSettings["SMTPUserName"].ToString(), ConfigurationManager.AppSettings["SMTPPassword"].ToString()); smtp.Credentials = credentials; smtp.UseDefaultCredentials = false; } else { smtp.UseDefaultCredentials = true; } if (ConfigurationManager.AppSettings["IISVersion"].ToString() == "7") smtp.DeliveryMethod = SmtpDeliveryMethod.Network; else smtp.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis; smtp.Send(mail); } finally { ApplicationSettings.RemoveSession(); } } catch (System.Data.SqlClient.SqlException) { returnValue.Success = false; returnValue.Message = Functions.SQLErrorMessage; } catch (Exception ex) { returnValue.Success = false; returnValue.Message = ex.Message; } return returnValue; }