public IActionResult Login([FromBody] loginClass login) { var user = new User(); user.user = "******"; user.Email = "indefinido"; user.UserId = "null"; user.token = "error"; if (login.CorreoElectronico != "*****@*****.**") { return(Ok(user.token)); } else { if (login.Contrasenia != "patito1234") { return(Ok(user.token)); } else { Console.WriteLine("Prueba Entrando 2"); var secretKey = _configuration.GetValue <string>("SecretKey"); var tokenHandler = new JwtSecurityTokenHandler(); var key = Encoding.ASCII.GetBytes(_configuration.GetValue <string>("SecretKey")); var tokenDescriptor = new SecurityTokenDescriptor { Subject = new ClaimsIdentity(new Claim[] { new Claim(ClaimTypes.NameIdentifier, "id1"), new Claim(ClaimTypes.Name, "Allan Quezada"), new Claim(ClaimTypes.Email, "*****@*****.**"), new Claim(ClaimTypes.Role, "1") }), // Nuestro token va a durar un día Expires = DateTime.UtcNow.AddDays(1), // Credenciales para generar el token usando nuestro secretykey y el algoritmo hash 256 SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature) }; var token = tokenHandler.CreateToken(tokenDescriptor); var hola = tokenHandler.WriteToken(token); user.user = "******"; user.Email = "Allan Quezada"; user.UserId = "id1"; user.token = hola; return(Ok(user)); } } return(Ok(user)); }
public List <loginClass> fetchUserLogin(String query) { List <loginClass> uList = new List <loginClass>(); String connString = "Data Source=localhost;Initial Catalog=AquariumTicketing;Integrated Security=true;pooling = true";//ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString.ToString(); // SqlConnection conn = new SqlConnection(connString); using (SqlConnection con = new SqlConnection(connString)) { if (con.State == ConnectionState.Closed) { con.Open(); } SqlCommand cmd = new SqlCommand(query, con); // conn.Open(); SqlDataReader reader = cmd.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { loginClass u = new loginClass(); u.username = reader.GetString(0); u.password = reader.GetString(1); uList.Add(u); //uList.Add(new User { firstName = reader.GetString(1), LastName = reader.GetString(2), Username = reader.GetString(3), Password = reader.GetString(4), isApproved = reader.GetInt32(5) }); } } con.Close(); } // DataTable dt = new DataTable(); return(uList); }