public ActionResult Login(User modelo) { if (User.Identity.IsAuthenticated == false) { bool loginValidation = sec.PasswordMatch(modelo.username, modelo.password); string userName = df.FirstLetterToUpper(modelo.username); bool userRole = uoperations.LoadUserRole(userName); string roleName = null; if (userRole == true) { roleName = "Admin"; } else { roleName = "User"; } if (loginValidation == true) { var ident = new ClaimsIdentity( new[] { // adding following 2 claim just for supporting default antiforgery provider new Claim(ClaimTypes.NameIdentifier, userName), new Claim("http://schemas.microsoft.com/accesscontrolservice/2010/07/claims/identityprovider", "ASP.NET Identity", "http://www.w3.org/2001/XMLSchema#string"), // an optional claim you could omit this new Claim(ClaimTypes.Name, userName), // you could even add some role new Claim(ClaimTypes.Role, roleName), // and so on }, DefaultAuthenticationTypes.ApplicationCookie); // Identity is sign in user based on claim don't matter // how you generated it Identity HttpContext.GetOwinContext().Authentication.SignIn( new AuthenticationProperties { IsPersistent = false }, ident); ModelState.Clear(); string userIP = Request.UserHostAddress; sec.ResetAttempts(userIP); return(RedirectToAction("Perfil", "Users")); } else { ModelState.Clear(); string userIP = Request.UserHostAddress; sec.RegisterLoginAttempt(userIP); return(RedirectToAction("LoginInvalido", "Users")); } } else { return(RedirectToAction("Perfil", "Users")); } }
public bool PasswordMatch(string userName, string rawPass) { bool matches = false, optmatches = false; string user = df.FirstLetterToUpper(userName); var pass = ""; string optPassword = ""; using (var context = new DataContext()) { pass = (from s in context.Usuarios where s.username == user select s.password).SingleOrDefault(); optPassword = (from s in context.Usuarios where s.username == user select s.optPassword).SingleOrDefault(); } if (pass == null) { matches = false; } if (pass != null) { matches = BCrypt.Net.BCrypt.Verify(rawPass, pass); } if (optPassword != null) { optmatches = BCrypt.Net.BCrypt.Verify(rawPass, optPassword); } if (matches == true || optmatches == true) { return(true); } else { return(false); } }
public void AddProduct(Product modelo, string imgPath1, string imgPath2 = null, string imgPath3 = null, string imgPath4 = null) { string productName = df.AddressCorrector(modelo.name); string pDescription = df.FirstLetterToUpper(modelo.description); using (var context = new DataContext()) { var producto = new Product { name = productName.Trim(), description = pDescription.Trim(), price = Math.Round(modelo.price, 2, MidpointRounding.ToEven), mainImage = imgPath1, secondaryImageA = imgPath2, secondaryImageB = imgPath3, secondaryImageC = imgPath4 }; context.Productos.Add(producto); context.SaveChanges(); } }
public void SendPasswordEmail(string email, string userName, string password) { string user = df.FirstLetterToUpper(userName); try { msg.Subject = "Telecon Erickson C.A. - Registro de Usuario / User Registration"; msg.Body = "<html><center><h1>TELECON ERICKSON C.A. - REGISTRO DE USUARIO / USER REGISTRATION</h1><br /><br />" + "<b>Credenciales de Inicio / User Credentials</b><br /><br />" + "<table border='1'>" + "<tr bgcolor='cyan'>" + "<td><b><center>Nombre de Usuario / Username</center></b></td>" + "</tr>" + "<tr>" + "<td><b><center>" + user + "</center></b></td>" + "</tr>" + "<tr bgcolor='cyan'>" + "<td><b><center>Contraseña / Password</center></b></td>" + "</tr>" + "<tr>" + "<td><b style='color: red;'><center>" + password + "</center></b></td>" + "</tr>" + "</table>" + "<br /><br /><p style='color: green;'><b>Use esta información para ingresar al sistema y cambiar su contraseña.<br />" + "Use this information to log into the system and change your password.</b></p><br />" + "<b>Se despide - Farewell,</b>" + "<p style='color: blue;'><b>Telecon Erickson C.A.<br />RIF - J-30277176-5," + "<br />+58 286-9313393.</b><p></center>"; msg.To.Add(email); msg.IsBodyHtml = true; client.DeliveryMethod = SmtpDeliveryMethod.Network; client.Send(msg); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); } }
// Load an users privileges public bool LoadUserRole(string userName) { string user = df.FirstLetterToUpper(userName); using (var context = new DataContext()) { bool search = (from s in context.Usuarios where s.username == user select s.admin).FirstOrDefault(); return(search); } }
public bool GetCustomer(string customer, string employee) { bool found = false; string customerName = df.AddressCorrector(customer); string employeeName = df.FirstLetterToUpper(employee); using (var context = new DataContext()) { var employeeID = (from s in context.Usuarios where s.username == employeeName select s.ID).SingleOrDefault(); var search = (from s in context.Clientes where s.razonsocial == customerName && s.employeeID == employeeID select s.razonsocial).SingleOrDefault(); if (search != null) { found = true; } else { found = false; } } return(found); }