Exemple #1
0
        protected void ASPxButtonLogin_Click(object sender, EventArgs e)
        {
            Page.Validate();

            if (!Page.IsValid)
            {
                return;
            }


            if (string.IsNullOrEmpty(recaptchaUserValue.Value))
            {
                Msg.Text = "Error en los datos de seguridad, vuelva a recargar la página.";
                return;
            }


            var Recaptchav3 = new RecaptchaVerificationHelper();

            // If your site is behind CloudFlare, be sure you're suing the CF-Connecting-IP header value instead:
            // https://support.cloudflare.com/hc/en-us/articles/200170986-How-does-Cloudflare-handle-HTTP-Request-headers

            RecaptchaVerificationResult recaptchaResult = Recaptchav3.VerifyRecaptchav3Response(
                Global.Configuration.Security.Google.Recaptcha.v3.GetGoogleRecaptchaSecretKey()
                , Global.Configuration.Security.Google.Recaptcha.v3.GetGoogleRecaptchaWebsiteKey()
                , Request.UserHostAddress
                , recaptchaUserValue.Value
                );

            if (recaptchaResult == RecaptchaVerificationResult.Success)
            {
                //divMessage.InnerHtml = "Score: " + Recaptchav3.Score;
                decimal?minScore = new decimal(0.6);
                if (Recaptchav3.Score < minScore)
                {
                    Response.Redirect("~/Captcha.aspx", true);
                }


                //create session
                // Global.Sessions.UserCreateSession();

                if (UsernameTextbox.Text.Equals(ConfigurationManager.AppSettings["Authentication:Credentials.User.Login"].ToString(), StringComparison.InvariantCulture) &&
                    PasswordTextbox.Text.Equals(ConfigurationManager.AppSettings["Authentication:Credentials.User.Password"].ToString(), StringComparison.InvariantCulture))
                {
                    Session["User.UserID"] = UsernameTextbox.Text;
                    Session.Timeout        = 60;
                    Response.Redirect("~/Admin/Main.aspx");
                }
                else
                {
                    Msg.Text = "Login failed. Please check your user name and password and try again.";
                }
            }
            else
            {
                Msg.Text = "Existe un problema para validar la seguridad, intente mas tarde o por favor contacte a soporte técnico.";
                return;
            }
        }
        protected void BootstrapButtonSend_Click(object sender, EventArgs e)
        {
            Page.Validate();

            if (!Page.IsValid)
            {
                return;
            }


            if (string.IsNullOrEmpty(recaptcha.Value))
            {
                Msg.Visible   = true;
                Msg.InnerHtml = "Error en los datos de seguridad, vuelva a recargar la página.";
                return;
            }


            var Recaptchav3 = new RecaptchaVerificationHelper();

            // If your site is behind CloudFlare, be sure you're suing the CF-Connecting-IP header value instead:
            // https://support.cloudflare.com/hc/en-us/articles/200170986-How-does-Cloudflare-handle-HTTP-Request-headers

            RecaptchaVerificationResult recaptchaResult = Recaptchav3.VerifyRecaptchav3Response(
                Global.Configuration.Security.Google.Recaptcha.v3.GetGoogleRecaptchaSecretKey()
                , Global.Configuration.Security.Google.Recaptcha.v3.GetGoogleRecaptchaWebsiteKey()
                , Request.UserHostAddress
                , recaptcha.Value
                );

            if (recaptchaResult == RecaptchaVerificationResult.Success)
            {
                //divMessage.InnerHtml = "Score: " + Recaptchav3.Score;
                decimal?minScore = new decimal(0.6);
                if (Recaptchav3.Score < minScore)
                {
                    Response.Redirect("~/Captcha.aspx", true);
                }


                //
                // format msg...
                //
                // IMPORANT:  Your smtp login email MUST be same as your FROM address.
                string[] to   = { Global.Configuration.Mail.GetEmailContacto() };
                string   from = Global.Configuration.Mail.GetMailServerLogin();
                //string[] CC;
                //string[] BCC;
                string domainName   = HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority);
                string emailSubject = "Formulario de Contacto Sitio Web " + domainName;
                bool   isBodyHtml   = false;
                string emailMessage = @"
----------------------------------------
- FORMULARIO PROBLEMAS AL PESAR
----------------------------------------
Nombre: " + Names.Text + Environment.NewLine + @"
Apellido: " + LastName.Text + Environment.NewLine + @"
Movil: " + Mobile.Text + Environment.NewLine + @"
Email: " + Email.Text + Environment.NewLine + @"
Cargo: " + Position.Text + Environment.NewLine + @"
Empresa: " + Business.Text + Environment.NewLine + @"
Ciudad: " + City.Text + Environment.NewLine + @"
Telefono: " + Telephone.Text + Environment.NewLine + @"
Inconveniente: " + Incident.SelectedItem.Value + Environment.NewLine + @"
Balanza: " + Balanza.Text + Environment.NewLine + @"
Capacidad: " + Capacidad.Text + Environment.NewLine + @"
Mensaje: " + Environment.NewLine + Notes.Text + Environment.NewLine + @"
--------------------------------------
";


                //var t = Task.Run( () => Global.Emails.SendEmailAsync(to, from, null, null, emailSubject, emailMessage, isBodyHtml) );
                //t.Wait();

                System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage()
                {
                    From            = new MailAddress(from, from, System.Text.Encoding.UTF8),
                    Subject         = emailSubject,
                    SubjectEncoding = System.Text.Encoding.UTF8,
                    Body            = emailMessage,
                    BodyEncoding    = System.Text.Encoding.UTF8,
                    IsBodyHtml      = isBodyHtml,
                    Priority        = MailPriority.Normal
                };

                mail.To.Add(to[0]);
                string msg;

                SmtpClient client = new SmtpClient
                {
                    Credentials = new System.Net.NetworkCredential(Global.Configuration.Mail.GetMailServerLogin(), Global.Configuration.Mail.GetMailServerPassword()),
                    Port        = Global.Configuration.Mail.GetMailServerPort(),
                    Host        = Global.Configuration.Mail.GetMailServer(),
                    EnableSsl   = Global.Configuration.Mail.GetMailServerIsEnableSSL()
                };
                try
                {
                    client.Send(mail);
                    msg = "Gracias, mensaje enviado...";
                    ClientScript.RegisterStartupScript(this.GetType(), "UserMsg", "alert('" + msg + "');", true);
                    Msg.Visible   = true;
                    Msg.InnerHtml = msg;
                }
                catch (Exception ex)
                {
                    Global.LogError(this.Context, Global.EnumLogCategories.EMAIL, ex.Message);
                    msg = "Lo sentimos, su mensaje no pudo ser enviado, intente mas tarde...";
                    ClientScript.RegisterStartupScript(this.GetType(), "UserMsg", "alert('" + msg + "');", true);
                    Msg.Visible   = true;
                    Msg.InnerHtml = msg;
                }
            }
            else
            {
                Msg.Visible   = true;
                Msg.InnerHtml = "Existe un problema para validar la seguridad, intente mas tarde o por favor contacte a soporte técnico.";
                return;
            }
        }
Exemple #3
0
        /*
         * protected void btnLogin_Click(object sender, EventArgs e) {
         *  if (Membership.ValidateUser(tbUserName.Text, tbPassword.Text)) {
         *      if(string.IsNullOrEmpty(Request.QueryString["ReturnUrl"])) {
         *          FormsAuthentication.SetAuthCookie(tbUserName.Text, false);
         *          Response.Redirect("~/");
         *      }
         *      else
         *          FormsAuthentication.RedirectFromLoginPage(tbUserName.Text, false);
         *  }
         *  else {
         *      tbUserName.ErrorText = "Invalid user";
         *      tbUserName.IsValid = false;
         *  }
         * }
         */


        protected void ASPxButtonLogin_Click(object sender, EventArgs e)
        {
            Page.Validate();

            if (!Page.IsValid)
            {
                return;
            }


            if (string.IsNullOrEmpty(recaptchaUserValue.Value))
            {
                Msg.Visible   = true;
                Msg.InnerHtml = "Error en los datos de seguridad, vuelva a recargar la página.";
                return;
            }


            var Recaptchav3 = new RecaptchaVerificationHelper();

            // If your site is behind CloudFlare, be sure you're suing the CF-Connecting-IP header value instead:
            // https://support.cloudflare.com/hc/en-us/articles/200170986-How-does-Cloudflare-handle-HTTP-Request-headers

            RecaptchaVerificationResult recaptchaResult = Recaptchav3.VerifyRecaptchav3Response(
                Global.Configuration.Security.Google.Recaptcha.v3.GetGoogleRecaptchaSecretKey()
                , Global.Configuration.Security.Google.Recaptcha.v3.GetGoogleRecaptchaWebsiteKey()
                , Request.UserHostAddress
                , recaptchaUserValue.Value
                );

            if (recaptchaResult == RecaptchaVerificationResult.Success)
            {
                //divMessage.InnerHtml = "Score: " + Recaptchav3.Score;
                decimal?minScore = new decimal(0.6);
                if (Recaptchav3.Score < minScore)
                {
                    Response.Redirect("~/Captcha.aspx", true);
                }


                //create session
                // Global.Sessions.UserCreateSession();

                // Go main menu.
                if (ValidateLogin())
                {
                    HttpCookie userid = new HttpCookie("User.Email", Email.Value.ToString())
                    {
                        Expires = DateTime.Now.AddYears(1)
                    };
                    Response.Cookies.Add(userid);

                    Response.Redirect("~/recursos/");
                }
                else
                {
                    Msg.Visible = true;
                }
                Msg.InnerHtml = "Login fallido. Por favor revise sus datos e intente de nuevo.";
            }
            else
            {
                Msg.Visible   = true;
                Msg.InnerHtml = "Existe un problema para validar la seguridad, intente mas tarde o por favor contacte a soporte técnico.";
            }



            bool ValidateLogin()
            {
                bool   loginOK = false;
                string salt = string.Empty, encrypass = string.Empty, dbpassword = string.Empty;

                SqlParameter[] parameters =
                {
                    new SqlParameter {
                        ParameterName = "Email", DbType = DbType.AnsiString, Size = 50, Value = Email.Value.ToString()
                    }
                };

                string tsql      = @"
SELECT TOP 1 
       [UserRegisterID]
      ,[Names]
      ,[LastName]
      ,[Email]
      ,[Password]
      ,[PasswordSalt]
  FROM [CMSUserRegister]
WHERE
Email = @Email 
ORDER BY [UserRegisterID] DESC
;";
                var    sqlserver = new SqlApiSqlClient();


                using (sqlserver.Connection = new SqlConnection(Global.Configuration.DB.GetConnectionStringDBMain()))
                {
                    using (var dr = sqlserver.DataReaderSqlString(tsql, parameters))
                    {
                        if (dr.Read())
                        {
                            salt       = dr["PasswordSalt"].ToString();;
                            dbpassword = dr["Password"].ToString();;


                            Byte[] _salt;
                            Byte[] _hash;

                            //This is the password policy that all passwords must adhere to, if the password doesn't meet the policy we save CPU processing time by not even bothering to calculate hash of a clearly incorrect password
                            PWDTK.PasswordPolicy PwdPolicy = new PWDTK.PasswordPolicy(numberUpper, numberNonAlphaNumeric, numberNumeric, minPwdLength, maxPwdLength);

                            //or we can just use the default password policy provided by the API like below
                            //PWDTK.PasswordPolicy PwdPolicy = PWDTK.cDefaultPasswordPolicy;

                            _salt = PWDTK.HashHexStringToBytes(salt); // reverse operation ;

                            //Generate the hash value
                            _hash = PWDTK.PasswordToHash(_salt, Password.Value.ToString(), iterations);

                            encrypass = PWDTK.HashBytesToHexString(_hash);


                            if (encrypass == dbpassword)
                            {
                                loginOK = true;

                                // Session["User.UserEmail"] = dr["UserEmail"].ToString();
                            }
                            else
                            {
                                loginOK = false;
                            }
                        }
                        else
                        {
                            loginOK = false;
                        }

                        dr.Close();
                    }

                    sqlserver.Connection.Close();
                };


                if (loginOK)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }