public bool ContainsUser(UserModel usermodel) { foreach (User item in GetUsers()) { if (item.Email.Equals(usermodel.Email) && item.Password.Equals(usermodel.Password)) { return true; } } return false; }
public ActionResult Signup(UserModel user) { if (ModelState.IsValid) { if(_repository.AddUser(user)) { if (user.Password != user.RepeatPassword) { ViewBag.Title = "Password doesn't match!"; return View(user); } return View("Information", user); } } ViewBag.Title = "Email is already in use!"; return View(user); }
public ActionResult Login(UserModel user) { if (ModelState.IsValid) { if(_repository.IsValid(user.Email, user.Password)) { FormsAuthentication.SetAuthCookie(user.Email, false); return RedirectToAction("Index", "Employee"); } else { ModelState.AddModelError("", "Login data is incorrect."); } } return View(user); }
public bool AddUser(UserModel user) { if(context.Users.FirstOrDefault(email => email.Email.Equals(user.Email)) == null) { var crypto = new SimpleCrypto.PBKDF2(); var encrPass = crypto.Compute(user.Password); User userToSave = context.Users.Create(); userToSave.Email = user.Email; userToSave.Password = encrPass; userToSave.PasswordSalt = crypto.Salt; userToSave.UserId = Guid.NewGuid(); context.Users.Add(userToSave); context.SaveChanges(); return true; } return false; }