示例#1
0
        protected void registrar_Click(object sender, EventArgs e)
        {
            prev = this.email.Text;
            var consulta = from m in db.Usuarios
                           where m.Email == prev
                           select m;

            foreach (var x in consulta)
            {
                previoemail = x.Email;
                //Label2.Text = previoemail;
            }


            string email = this.email.Text;
            Regex  regex = new Regex(@"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$");
            Match  match = regex.Match(email);

            if (match.Success)
            {
                Usuario nuevo = new Usuario();
                nuevo.Nombre           = nombre.Text;
                nuevo.Apodo            = apodo.Text;
                nuevo.Ciudad           = ciudad.Text;
                nuevo.Telefono         = telefono.Text;
                nuevo.Email            = this.email.Text;
                nuevo.Nombre_Mascota   = nombre_mascota.Text;
                nuevo.Password         = password.Text;
                nuevo.Fecha_Nacimiento = dia.Text + "/" + mes.Text + "/" + año.Text;
                //nuevo.Imagen_Perfil = ruta;
                confirmar   = conpassword.Text;
                Label1.Text = "";

                string pass    = password.Text;
                string mascota = nombre_mascota.Text;
                if (pass.Length >= 8)
                {
                    //Regex regex2 = new Regex(@"^(([0-9]+)([A-Z]+)([a-z]+)([!@#$%^&*()_+=\[{\]};:<>|./?,-]))$");
                    //Regex regex2 = new Regex("^(?=.*[a-z])(?=.*[A-Z])(?=.*[^a-zA-Z]).{8,}$");
                    Regex regex2 = new Regex("^(?=.*[a-z])(?=.*[!@#$%^&*()_+<>|./?,-])(?=.*[A-Z])(?=.*[^a-zA-Z]).{8,}$");
                    Match match2 = regex2.Match(pass);
                    if (match2.Success)
                    {
                        if (nuevo.Password == confirmar)
                        {
                            if (mascota.Length > 0)
                            {
                                if (previoemail != this.email.Text)
                                {
                                    string d = dia.Text, m = mes.Text, a = año.Text;
                                    if (d.Length > 0 && m.Length > 0 && a.Length > 0)
                                    {
                                        int diferencia = 2019 - int.Parse(año.Text);
                                        //int difdia = 09, difmes=04;
                                        // string diauser = dia.Text, mesuser=mes.Text;
                                        //       DateTime fecha =Convert.ToDateTime(dia.Text+mes.Text+año.Text);
                                        //Label15 = fecha;
                                        if (diferencia >= 18)
                                        {
                                            if (FileUpload1.HasFile)
                                            {
                                                //si hay una archivo.
                                                string nombreArchivo = FileUpload1.FileName;
                                                string ruta          = "~/Imagenes/Perfil/" + nombreArchivo;
                                                FileUpload1.SaveAs(Server.MapPath(ruta));
                                                //encriptamos la cadena inicial
                                                password.Text       = Seguridad.Encriptar(pass);
                                                nuevo.Password      = password.Text;
                                                nuevo.Imagen_Perfil = ruta;
                                                //Label3.Text = "Se guardó la imagen. y su ruta es" + Environment.NewLine + ruta;
                                                db.Usuarios.Add(nuevo);
                                                db.SaveChanges();
                                                Response.Redirect("Login.aspx");
                                            }
                                            else
                                            {
                                                Label3.Text    = "No se eligio Imagen";
                                                nomascota.Text = "";
                                                nopass.Text    = "";
                                                nopass2.Text   = "";
                                                newfecha.Text  = "";
                                            }
                                        }
                                        else
                                        {
                                            newfecha.Text  = "Debes ser mayor de edad";
                                            nomascota.Text = "";
                                            nopass.Text    = "";
                                            nopass2.Text   = "";
                                        }
                                    }
                                    else
                                    {
                                        newfecha.Text  = "Indica una fecha";
                                        nomascota.Text = "";
                                        nopass.Text    = "";
                                        nopass2.Text   = "";
                                    }
                                }
                                else
                                {
                                    Label1.Text    = "Email ya registrado";
                                    nomascota.Text = "";
                                    nopass.Text    = "";
                                    nopass2.Text   = "";
                                }
                            }
                            else
                            {
                                nomascota.Text = "Indica un nombre";
                                nopass.Text    = "";
                                nopass2.Text   = "";
                                Label1.Text    = "";
                            }
                        }
                        else
                        {
                            nopass.Text  = "Contraseñas no iguales";
                            nopass2.Text = "Contraseñas no iguales";
                            //password.Text = "";
                            conpassword.Text = "";
                            Label1.Text      = "";
                        }
                    }
                    else
                    {
                        nopass.Text  = "Deben ser Minimo 8 caracteres, 1 Mayuscula, 1 Minuscula, 1 Numero, 1 Simbolo";
                        nopass2.Text = "Deben ser Minimo 8 caracteres, 1 Mayuscula, 1 Minuscula, 1 Numero, 1 Simbolo";
                    }
                }
                else
                {
                    nopass.Text  = "Deben ser Minimo 8 caracteres, 1 Mayuscula, 1 Minuscula, 1 Numero, 1 Simbolo";
                    nopass2.Text = "Deben ser Minimo 8 caracteres, 1 Mayuscula, 1 Minuscula, 1 Numero, 1 Simbolo";
                }
            }
            else
            {
                Label1.Text = "Email no cumple el formato requerido ([email protected])";
            }
        } //fin funcion
示例#2
0
        protected void Actualizar_Click(object sender, EventArgs e)
        {
            confirmar = mod_confpassword.Text;
            Regex regex2 = new Regex("^(?=.*[a-z])(?=.*[!@#$%^&*()_+<>|./?,-])(?=.*[A-Z])(?=.*[^a-zA-Z]).{8,}$");
            Match match2 = regex2.Match(mod_password.Text);

            if (match2.Success)
            {
                if (mod_password.Text == confirmar)
                {
                    string modif_id = Session["user"].ToString();
                    var    query    = (from a in db.Usuarios
                                       where a.Email == modif_id
                                       select a).FirstOrDefault();

                    query.Nombre   = mod_nombre.Text;
                    query.Apodo    = mod_apodo.Text;
                    query.Ciudad   = mod_ciudad.Text;
                    query.Telefono = mod_telefono.Text;
                    query.Password = Seguridad.Encriptar(mod_password.Text);
                    //query.Imagen_Perfil = ruta;
                    if (FileUpload1.HasFile)
                    {
                        //si hay una archivo.
                        string nombreArchivo = FileUpload1.FileName;
                        string ruta          = "~/Imagenes/Perfil/" + nombreArchivo;
                        FileUpload1.SaveAs(Server.MapPath(ruta));
                        query.Imagen_Perfil = ruta;

                        if (test.Text == confirmar)
                        {
                            //mod_password.Text = Seguridad.Encriptar(mod_password.Text);
                            // query.Password = mod_password.Text;
                            db.SaveChanges();
                            //File.SetAttributes(ruta_old, FileAttributes.Normal);
                            //File.Delete(ruta_old);
                            Response.Redirect("Panel_Usuario.aspx");
                        }
                        else
                        {
                            db.SaveChanges();
                            Session.Remove("user");
                            Response.Redirect("Login.aspx");
                        }
                    }
                    else
                    {
                        if (test.Text == confirmar)
                        {
                            db.SaveChanges();
                            Response.Redirect("Panel_Usuario.aspx");
                        }
                        else
                        {
                            db.SaveChanges();
                            Session.Remove("user");
                            Response.Redirect("Login.aspx");
                        }
                    }
                }
                else
                {
                    mod_nopass.Text  = "Contraseñas no iguales";
                    mod_nopass2.Text = "Contraseñas no iguales";
                }
            }
            else
            {
                mod_nopass.Text  = "Deben ser Minimo 8 caracteres, 1 Mayuscula, 1 Minuscula, 1 Numero, 1 Simbolo";
                mod_nopass2.Text = "Deben ser Minimo 8 caracteres, 1 Mayuscula, 1 Minuscula, 1 Numero, 1 Simbolo";
            }
        }