Exemple #1
0
        public void RecoverClick()
        {
            string strEmail = txtEmail.Text;

            BusinessServices.User objUser = new BusinessServices.User();
            DataTable             dtbUser = objUser.GetDetailsByEmailAndDomain(strEmail, HttpContext.Current.Request.Url.Host.ToString());

            //DataTable dtbUser = objUser.GetDetailsByEmailAndDomain(strEmail, "demo.saltcompliance.com");

            if (dtbUser.Rows.Count > 0 && Convert.ToBoolean(dtbUser.Rows[0]["Active"]))
            {
                // found user - gather details
                string strFirstName = dtbUser.Rows[0]["FirstName"].ToString();
                string strLastName  = dtbUser.Rows[0]["LastName"].ToString();
                string strUserName  = dtbUser.Rows[0]["UserName"].ToString();
                string strPassword  = dtbUser.Rows[0]["Password"].ToString();
                string strUserId    = dtbUser.Rows[0]["UserID"].ToString();
                //Password encryption code
                string inputString       = strPassword + DateTime.Now;
                SHA256 sha256            = SHA256Managed.Create();
                byte[] bytes             = Encoding.UTF8.GetBytes(inputString);
                byte[] hash              = sha256.ComputeHash(bytes);
                string encryptedPassword = GetStringFromHash(hash);

                //Insert code for SP to insert new encrypted password
                objUser.UpdateEncryptedPassword(strUserName, encryptedPassword);


                string strFromName  = ApplicationSettings.AppName;
                string strFromEmail = ApplicationSettings.SupportEmail;

                BusinessServices.Email objEmail = new BusinessServices.Email();
                string strHREF          = "";
                string RedirectionCheck = Request.QueryString["Rdct"];
                string strBody          = "";

                DataTable dtbOrgDisablePassword;
                string    strDisabledpass = "";
                dtbOrgDisablePassword = objUser.GetUserOrganisationPasswordLock(HttpContext.Current.Request.Url.Authority.ToString());
                //dtbOrgDisablePassword = objUser.GetUserOrganisationPasswordLock("demo.saltcompliance.com");
                if (dtbOrgDisablePassword.Rows.Count > 0)
                {
                    if (dtbOrgDisablePassword.Rows[0]["PasswordLockout"].ToString().Trim().ToLower() == "true")
                    {
                        strDisabledpass = "******";
                    }
                    else
                    {
                        strDisabledpass = "";
                    }
                }
                if (strDisabledpass == "Disabled")
                {
                    strHREF = "";
                    strBody = GetBodyUniqueURL(strFirstName, strLastName, strUserName, strPassword, strUserId, encryptedPassword, strHREF);
                }
                else if (RedirectionCheck == "UniqueURL")
                {
                    //strHREF = "http://localhost:51864/Default.aspx?AutoLgnUSID=" + strUserId + "&AutoLgnPass="******"https://" + HttpContext.Current.Request.Url.Host + "/Default.aspx?AutoLgnUSID=" + strUserId + "&AutoLgnPass="******"https://" + HttpContext.Current.Request.Url.Host + "/ChangePassword.aspx?UID=" + strUserId + "&P=" + encryptedPassword;
                    strBody = GetBody(strFirstName, strLastName, strUserName, strPassword, strUserId, encryptedPassword, strHREF);
                }

                try
                {
                    // Found user send email
                    objEmail.SendEmail(strEmail, strFirstName + " " + strLastName, strFromEmail, strFromName, null, null, ResourceManager.GetString("EmailSubject"), strBody, ApplicationSettings.MailServer);
                    lblMessage.Text     = String.Format(ResourceManager.GetString("lblMessage.Sent"), strEmail); //"Login Information has been sent to:<BR>" + strEmail;
                    lblMessage.CssClass = "WarningMessage";
                    btnRecover.Visible  = false;
                    txtEmail.Visible    = false;
                    lblText.Visible     = false;
                }
                catch (Exception ex)
                {
                    // Found user but unable to send email
                    lblMessage.Text     = ResourceManager.GetString("UserNotFound") + ex.Message;
                    lblMessage.CssClass = "WarningMessage";
                    btnRecover.Visible  = false;
                    txtEmail.Visible    = false;
                }
            }
            else
            {
                // inactive user : user not found
                lblMessage.Text     = ResourceManager.GetString(dtbUser.Rows.Count > 0 ? "lblMessage.Inactive" : "lblMessage.NotFound");
                lblMessage.CssClass = "WarningMessage";
            }
        }