//public ActionResult Create(FormCollection collection) public ActionResult Create(Usuario usuario) { //proban // try { // byte[] byteArr = { 0, 16, 104, 213 }; // TODO: Add insert logic here // Usuario usuario = new Usuario(); // usuario.ClaveTexto ="nvis"; usuario.Clave = EncriptacionHelper.EncriptarByte(usuario.ClaveTexto); new UsuarioLN().InsertarUsuario(usuario); return(RedirectToAction("Index")); ///return RedirectToAction("Index"); } catch { return(View()); } }
public int GetUsuarioId(string pUsuario, string pPassword) { try { // string UserPass = Utilitario.GetMd5Hash2(pPassword); byte[] UserPass = EncriptacionHelper.EncriptarByte(pPassword); int returnedVal = 0; using (SqlConnection conexion = new SqlConnection(ConfigurationManager.ConnectionStrings[ConfigurationManager.AppSettings["cnnSql"]].ConnectionString)) { using (SqlCommand comando = new SqlCommand("paUsuario_BuscaCodUserClave", conexion)) { comando.CommandType = CommandType.StoredProcedure; comando.Parameters.AddWithValue("@ParamUsuario", pUsuario); comando.Parameters.AddWithValue("@ParamPass", UserPass); conexion.Open(); returnedVal = Convert.ToInt32(comando.ExecuteScalar()); conexion.Close(); } } return(Convert.ToInt32(returnedVal)); } catch (Exception ex) { string innerException = (ex.InnerException == null) ? "" : ex.InnerException.ToString(); //Logger.paginaNombre = this.GetType().Name; //Logger.Escribir("Error en Logica de Negocio: " + ex.Message + ". " + ex.StackTrace + ". " + innerException); return(-1); } }
public async Task ValidateAsync(ResourceOwnerPasswordValidationContext context) { var user = await userRepository.GetAsync(context.UserName, EncriptacionHelper.EncryptToByte(context.Password)); if (user != null) { context.Result = new GrantValidationResult(user.PkId.ToString(), authenticationMethod: "custom", claims: GetUserClaims(user)); } else { context.Result = new GrantValidationResult(TokenRequestErrors.InvalidGrant, "Invalid Credentials"); } //return Task.FromResult(context.Result); }
public ActionResult Edit(int id, Usuario usuario) { try { // TODO: Add update logic here usuario.Clave = EncriptacionHelper.EncriptarByte(usuario.ClaveTexto); new UsuarioLN().EditarUsuario(id, usuario); return(RedirectToAction("Index")); } catch { return(View()); } }
public Usuarios InsertarUsuario(Usuarios usuario) { byte[] UserPass = EncriptacionHelper.EncriptarByte(usuario.ClaveTxt); usuario.Clave = UserPass; using (SqlConnection conexion = new SqlConnection(ConfigurationManager.ConnectionStrings[ConfigurationManager.AppSettings["cnnSql"]].ConnectionString)) { using (SqlCommand comando = new SqlCommand("paUsuario_insertar", conexion)) { comando.CommandType = System.Data.CommandType.StoredProcedure; comando.Parameters.AddWithValue("@Clave", usuario.Clave); comando.Parameters.AddWithValue("@CodUsuario", usuario.CodUsuario); comando.Parameters.AddWithValue("@Nombres", usuario.Nombres); comando.Parameters.AddWithValue("@IdRol", usuario.IdRol); conexion.Open(); usuario.IdUsuario = Convert.ToInt32(comando.ExecuteScalar()); conexion.Close(); } } return(usuario); }
public async Task <IActionResult> Login(User model, string button) { if (ModelState.IsValid) { // validate username/password against in-memory store //if (_users.ValidateCredentials(model.Username, model.Password)) if (await userValidator.ValidateCredentialsAsync(model.Username, EncriptacionHelper.EncryptToByte(model.PasswordTexto))) { var user = await userValidator.FindByUsernameAsync(model.Username); await _events.RaiseAsync(new UserLoginSuccessEvent(user.Username, user.Id.ToString(), user.Username)); // issue authentication cookie with subject ID and username var isuser = new IdentityServerUser(user.Id.ToString()) { DisplayName = user.Username }; AuthenticationProperties props = null; await HttpContext.SignInAsync(isuser, props); //if (context != null) //{ // if (context.IsNativeClient()) // { // // The client is native, so this change in how to // // return the response is for better UX for the end user. // return this.LoadingPage("Redirect", model.ReturnUrl); // } // // we can trust model.ReturnUrl since GetAuthorizationContextAsync returned non-null // return Redirect(model.ReturnUrl); //} // request for a local page if (Url.IsLocalUrl(model.ReturnUrl)) { return(Redirect(model.ReturnUrl)); } else if (string.IsNullOrEmpty(model.ReturnUrl)) { return(Redirect("~/")); } else { // user might have clicked on a malicious link - should be logged throw new Exception("invalid return URL"); } } //await _events.RaiseAsync(new UserLoginFailureEvent(model.Username, "invalid credentials", clientId: context?.Client.ClientId)); //ModelState.AddModelError(string.Empty, AccountOptions.InvalidCredentialsErrorMessage); } // something went wrong, show form with error //var vm = await BuildLoginViewModelAsync(model); return(View(model)); }
public async Task <bool> ValidateCredentialsAsync(string username, byte[] password) { var user = await repository.GetAsync(username, EncriptacionHelper.EncryptToByte(password)); return(user != null); }