Exemplo n.º 1
0
        private string ForgotPasswordUpdate(Cuenta user)
        {
            string password = Guid.NewGuid().ToString("N").ToLower()
                              .Replace("1", "").Replace("o", "").Replace("0", "")
                              .Substring(0, 10);
            string salt = PassSalt.Create();
            string hash = PassHash.Create(password, salt);

            user.Passwd = hash;
            user.Salt   = salt;
            _context.SaveChanges();

            return(password);
        }
Exemplo n.º 2
0
        public bool ActualizarPassword(string email, string passwordAntiguo, string passwordActual)
        {
            var    c      = _context.Cuenta.SingleOrDefault(x => x.Email == email);
            Cuenta cuenta = VerificarLogin(c.Usuario, passwordAntiguo);

            if (cuenta != null)
            {
                string salt = PassSalt.Create();
                string hash = PassHash.Create(passwordActual, salt);
                cuenta.Passwd = hash;
                cuenta.Salt   = salt;
                _context.SaveChanges();
                return(true);
            }
            return(false);
        }
 public IActionResult Add(AdministradorViewModel model)
 {
     if (ModelState.IsValid)
     {
         var cookieValue = Request.Cookies["UrlFacultad"];
         multyTenancyService.SeleccionarNodoFacultad(cookieValue);
         string salt = PassSalt.Create();
         string hash = PassHash.Create(model.Password, salt);
         var    a    = new Administrador()
         {
             Nombre   = model.Nombre,
             Apellido = model.Apellido,
             Usuario  = model.Usuario,
             Passwd   = hash,
             Salt     = salt,
         };
         userService.AddAdministrador(a, model.Tipo_Administrador, model.Facultad);
         return(RedirectToAction("Index"));
     }
     return(View(model));
 }
Exemplo n.º 4
0
        public bool CrearCuentaAdministrador(string nombre, string apellido, string usuario, string password, string tipoAdministrador, int IdFacultad)
        {
            try {
                var salt          = PassSalt.Create();
                var hash          = PassHash.Create(password, salt);
                var administrador = new Administrador()
                {
                    Nombre   = nombre,
                    Apellido = apellido,
                    Usuario  = usuario,
                    Passwd   = hash,
                    Salt     = salt
                };
                _contextoGeneral.Administrador.Add(administrador);
                _contextoGeneral.SaveChanges();

                if (tipoAdministrador == "Facultad")
                {
                    var tipoAdminFac = new AdministradorFacultad()
                    {
                        FacultadId      = IdFacultad,
                        AdministradorId = administrador.Id
                    };
                    _contextoGeneral.AdministradorFacultad.Add(tipoAdminFac);
                }
                else
                {
                    var tipoAdminUdelar = new AdministradorUdelar()
                    {
                        AdministradorId = administrador.Id
                    };
                    _contextoGeneral.AdministradorUdelar.Add(tipoAdminUdelar);
                }
                _contextoGeneral.SaveChanges();
            } catch (Exception ex) {
                Console.WriteLine(ex);
                return(false);
            }
            return(true);
        }
Exemplo n.º 5
0
        public bool CrearCuenta(CreateUserRequest model)
        {
            if (model.GoogleId == null)                                 //Register Interno
            {
                if (!VerificarCuentaDatos(model.Usuario, model.Cedula)) //si esto es falso osea que no hay datos existentes
                {
                    var salt = PassSalt.Create();
                    var hash = PassHash.Create(model.Password, salt);
                    try {
                        var persona = new Persona()
                        {
                            Ci       = model.Cedula,
                            Nombre   = model.Nombre,
                            Apellido = model.Apellido,
                        };
                        _context.Persona.Add(persona);
                        _context.SaveChanges();

                        var cuenta = new Cuenta()
                        {
                            Usuario        = model.Usuario,
                            Passwd         = hash, //Hash
                            Salt           = salt, //Salt
                            Email          = model.Email,
                            NumeroTelefono = model.Telefono,
                            TipoCuenta     = model.TipoCuenta,
                            PersonaId      = persona.Id,
                        };
                        _context.Cuenta.Add(cuenta);
                        _context.SaveChanges();

                        return(true);
                    } catch (Exception ex) {
                        Console.WriteLine(ex);
                        return(false);
                    }
                }
            }
            else    //Register google
            {
                var user = VerificarCuentaGoogle(model.GoogleId);
                if (user == null)
                {
                    var persona = new Persona()
                    {
                        Ci       = model.Cedula,
                        Nombre   = model.Nombre,
                        Apellido = model.Apellido,
                    };
                    _context.Persona.Add(persona);
                    _context.SaveChanges();

                    var cuenta = new Cuenta()
                    {
                        Usuario        = model.GoogleId,
                        Email          = model.Email,
                        NumeroTelefono = model.Telefono,
                        TipoCuenta     = model.TipoCuenta,
                        PersonaId      = persona.Id,
                    };
                    _context.Cuenta.Add(cuenta);
                    _context.SaveChanges();

                    var cunetaGoogle = new CuentaGoogle()
                    {
                        CuentaId = cuenta.Id,
                        GoogleId = model.GoogleId,
                        ImgUrl   = model.ImgUrl
                    };
                    _context.CuentaGoogle.Add(cunetaGoogle);
                    _context.SaveChanges();
                    return(true);
                }
            }

            return(false);
        }