Esempio n. 1
0
        /// <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>
        /// Change Password method.
        /// </summary>
        /// <returns></returns>
        public ReturnValue ChangePassword(Guid logonId, string userName, string password, string newPassword)
        {
            ReturnValue returnValue = new ReturnValue();

            try
            {
                Host.LoadLoggedOnUser(logonId);

                try
                {
                    switch (UserInformation.Instance.UserType)
                    {
                        case DataConstants.UserType.Staff:
                                throw new Exception("Access denied");
                        case DataConstants.UserType.Client:
                        case DataConstants.UserType.ThirdParty:
                            // Can do everything
                            break;
                        default:
                            throw new Exception("Access denied");
                    }

                    SrvPassword srvPassword = new SrvPassword();
                    srvPassword.Load(userName);
                    srvPassword.OriginalPassword = password;
                    srvPassword.NewPassword = newPassword;
                    srvPassword.RepeatPassword = newPassword;
                    srvPassword.RequireChange = false;
                    string error;

                    if (srvPassword.ValidateAll(out error))
                    {
                        srvPassword.Save(out error);
                    }

                    if (error == string.Empty)
                    {
                        returnValue.Success = true;
                    }
                    else
                    {
                        returnValue.Success = false;
                        returnValue.Message = error;
                    }

                }
                finally
                {
                    // Remove the logged on user's ApplicationSettings from the
                    // list of concurrent sessions
                    Host.UnloadLoggedOnUser();

                }

            }
            catch (System.Data.SqlClient.SqlException)
            {
                returnValue.Success = false;
                returnValue.Message = Functions.SQLErrorMessage;
            }
            catch (Exception ex)
            {
                returnValue.Success = false;
                returnValue.Message = ex.Message;
            }

            return returnValue;
        }
Esempio n. 3
0
        /// <summary>
        /// Change Password method.
        /// </summary>
        /// <returns></returns>
        public ReturnValue ChangePassword(Guid logonId, string userName, string password, string newPassword)
        {
            ReturnValue returnValue = new ReturnValue();

            try
            {
                Host.LoadLoggedOnUser(logonId);

                try
                {
                    switch (UserInformation.Instance.UserType)
                    {
                    case DataConstants.UserType.Staff:
                        throw new Exception("Access denied");

                    case DataConstants.UserType.Client:
                    case DataConstants.UserType.ThirdParty:
                        // Can do everything
                        break;

                    default:
                        throw new Exception("Access denied");
                    }

                    SrvPassword srvPassword = new SrvPassword();
                    srvPassword.Load(userName);
                    srvPassword.OriginalPassword = password;
                    srvPassword.NewPassword      = newPassword;
                    srvPassword.RepeatPassword   = newPassword;
                    srvPassword.RequireChange    = false;
                    string error;

                    if (srvPassword.ValidateAll(out error))
                    {
                        srvPassword.Save(out error);
                    }

                    if (error == string.Empty)
                    {
                        returnValue.Success = true;
                    }
                    else
                    {
                        returnValue.Success = false;
                        returnValue.Message = error;
                    }
                }
                finally
                {
                    // Remove the logged on user's ApplicationSettings from the
                    // list of concurrent sessions
                    Host.UnloadLoggedOnUser();
                }
            }
            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;
        }