Ejemplo n.º 1
0
        public ActionResult Password(NewPassword pass)
        {
            NewPassword claspass = new NewPassword();

            if (pass.newcontrasena.Length > 15)
            {
                ModelState.AddModelError("newcontrasena", "Maximo de caracteres 15");
            }

            if (pass.newcontrasena.Length < 6)
            {
                ModelState.AddModelError("newcontrasena", "Minimo de caracteres 6");
            }

            if (ModelState.IsValid)
            {
                try
                {
                    if (pass.newcontrasena == pass.newcontrasena2)
                    {
                        var UserLogin = (usuario)Session["User"];
                        int idUser    = Convert.ToInt32(UserLogin.id_usuario);
                        pass.contrasena = HelperHash.MD5(pass.contrasena);
                        usuario user = db.usuario.Where(x => x.id_usuario == idUser).SingleOrDefault();
                        if (user.contrasena == pass.contrasena)
                        {
                            pass.newcontrasena = HelperHash.MD5(pass.newcontrasena);
                            user.contrasena    = pass.newcontrasena;

                            bool rpta = claspass.guardarpass(user);
                            if (rpta)
                            {
                                return(RedirectToAction("Index"));
                            }
                            else
                            {
                                return(View(pass));
                            }
                        }
                        else
                        {
                            ModelState.AddModelError("contrasena", "La contraseña es incorrecta");
                        }
                    }
                    else
                    {
                        //ModelState.AddModelError("newcontrasena", "Lcontraseña es incorrecta");
                        ModelState.AddModelError("newcontrasena2", "La nueva contraseña no coincide");
                    }
                }
                catch (Exception)
                {
                    throw;
                }
            }

            return(View(pass));
        }
Ejemplo n.º 2
0
        public async Task <ActionResult> Edit([Bind(Include = "Secret,Name,ApplicationType,Active,RefreshTokenLifeTime,AllowedOrigin")] Client client)
        {
            if (ModelState.IsValid)
            {
                client.Secret = HelperHash.GetHash(client.Secret);
                _service.Repository.Update(client);
                await _service.UnitOfWork.SaveAsync();

                return(RedirectToAction("Index"));
            }
            return(View(client));
        }
        public async Task <IActionResult> OnGetAsync(string paramUsername, string paramPassword)
        {
            if (string.IsNullOrEmpty(paramUsername) || string.IsNullOrEmpty(paramPassword))
            {
                return(LocalRedirect("/"));
            }
            string returnUrl = Url.Content("~/");

            try
            {
                // Clear the existing external cookie
                await HttpContext
                .SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
            }
            catch { }

            string passwordHash = HelperHash.HashString(paramPassword);

            using var context = new AggregatorContext();
            var adminUser = await context !.AdminUsers !.FirstOrDefaultAsync(l => l.Login == paramUsername && l.Password == passwordHash);

            if (adminUser != null)
            {
                var claims = new List <Claim>
                {
                    new Claim(ClaimTypes.Name, paramUsername),
                    new Claim(ClaimTypes.Role, "Administrator"),
                };
                var claimsIdentity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme);
                var authProperties = new AuthenticationProperties
                {
                    IsPersistent = true,
                    RedirectUri  = this.Request.Host.Value
                };
                try
                {
                    await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme,
                                                  new ClaimsPrincipal(claimsIdentity),
                                                  authProperties);
                }
                catch (Exception ex)
                {
                    string error = ex.Message;
                    throw;
                }
                return(LocalRedirect(returnUrl));
            }
            return(LocalRedirect("/"));
        }
Ejemplo n.º 4
0
        public ActionResult Create([Bind(Include = "id_usuario,nombre_user,apellido_user,email,contrasena,estado,imagen,id_rol, usuario_cedula")] usuario usuario)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    usuario.contrasena = "Contrasena123";


                    usuario.contrasena = HelperHash.MD5(usuario.contrasena);
                    usuario.estado     = true;
                    db.usuario.Add(usuario);

                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
                //catch (Exception)
                //{
                //    ModelState.AddModelError("nombre_user", "Erro al guardar");
                //    //throw;
                //}
                catch (DbEntityValidationException ex)
                {
                    List <string> errorMessages = new List <string>();
                    List <string> newMessages   = new List <string>();
                    //((System.Data.Entity.Validation.DbEntityValidationException)$dbEx).EntityValidationErrors;

                    foreach (DbEntityValidationResult validationResult in ex.EntityValidationErrors)
                    {
                        string entityName = validationResult.Entry.Entity.GetType().Name;
                        foreach (DbValidationError error in validationResult.ValidationErrors)
                        {
                            errorMessages.Add(entityName + "." + error.PropertyName + ": " + error.ErrorMessage);
                        }
                    }
                    //respuesta.Respuesta = false;
                    //respuesta.ListaError = errorMessages;
                    newMessages = errorMessages;
                }
            }


            ViewBag.id_rol = new SelectList(db.rol, "id_rol", "rol1", usuario.id_rol);
            return(View(usuario));
        }
Ejemplo n.º 5
0
        public async Task <object> PremiumInfo()
        {
            string accessTokenOnAggregator = premiumInfoValidationService.CheckAndGetAccessTokenOnAggregator(Request);
            string atHash = HelperHash.AtHashString(accessTokenOnAggregator);

            var authorizationState = await authorizationStateService.GetAuthStateByTokenAsync(atHash);

            var servingOperator = idgwConnectorManager.GetServingOperatorByString(authorizationState !.PremiumInfoToken.ServingOperator !);
            var idgwConnector   = idgwConnectorManager[servingOperator];

            var idgwResponse = await idgwConnector !.PremiumInfoAsync(authorizationState !.PremiumInfoToken.AccessTokenOnIdgw !);
            var idgwJwks     = await idgwConnector.GetJwksAsync();

            var jwtSecurityTokenHandler = new JwtSecurityTokenHandler();

            if (jwtSecurityTokenHandler.CanReadToken(idgwResponse))
            {
                if (!JwtSignatureValidator.Validate(idgwResponse, idgwJwks, out var idClaims))
                {
                    throw new UnifiedException(OAuth2Error.UnauthorizedClient);
                }
                var jwtPayload = jwtSecurityTokenHandler.ReadJwtToken(idgwResponse).Payload;

                if (authorizationState !.IsPremiumInfoSigned)
                {
                    return(SignedJwtCreator.Create(jwtPayload, settings.PrivateKey !));
                }
                return(jwtPayload);
            }

            if (authorizationState !.IsPremiumInfoSigned)
            {
                var newPayload = JwtPayload.Deserialize(idgwResponse);

                return(SignedJwtCreator.Create(newPayload, settings.PrivateKey !));
            }
            var idgwResponseJson = JsonDocument.Parse(idgwResponse);

            if (idgwResponseJson != null)
            {
                return(idgwResponseJson);
            }
            return(idgwResponse);
        }
Ejemplo n.º 6
0
        public ActionResult index(string email, string password)
        {
            if (email == null && password == null)
            {
                return Redirect("~/Login/index");
            }
            try
            {
                using (var Contex = new Farmacia_FarmalivioEntities())
                {
//                    var usuario = new usuario();
                    password = HelperHash.MD5(password);
                    var usuario = Contex.usuario.Include("rol")
                                  .Where(x => x.email == email && x.contrasena == password && x.estado==true)
                                  .FirstOrDefault();
                    if (usuario == null)
                    {
                        ViewBag.error = "La contraseña o correo no es valido";
                        return View("index");
                    }
                    Session["User"] = usuario;
                  
                }
                var UserLogin = (usuario)Session["User"];
                //Session["Nombreusuario"] = UserLogin.nombre_user + " " + UserLogin.apellido_user;
                //Session["imagen"] = UserLogin.imagen;
                //string nameUser = UserLogin.nombre_user + " " + UserLogin.apellido_user;
                return Redirect("~/inicio/index/");
            }
            catch (Exception e)
            {
                throw;
                //ViewBag.error = "La contraseña o correo no es valido";
                //return View("index");
  
            }
        }