public ActionResult ChangePassword(ChangePasswordViewModel model) { bool updated = false; if (ModelState.IsValid) { if (model.NewPassword == model.ConfirmPassword) { var userObject = db.Users.Where(d => d.Email == User.Identity.Name).FirstOrDefault(); if (userObject != null) { userObject.Password = EncrypterDecrypter.Encrypt(model.NewPassword); db.SaveChanges(); updated = true; } else { updated = false; ModelState.AddModelError("", "Please enter valid information"); } } } else { updated = false; ModelState.AddModelError("", "Please enter valid information"); } ViewBag.UpdateMessage = updated == true ? "Successfully updated" : ""; return(View(model)); }
public ActionResult Register(User user) { user.CreatedDate = DateTime.Now; user.UpdatedDate = DateTime.Now; user.LinkExpiryDate = DateTime.Now; user.IsActive = true; user.CreatedBy = 1; user.UpdatedBy = 1; user.UserRoleID = 3; user.Password = EncrypterDecrypter.Encrypt(user.Password); var objUser = db.Users.Where(d => d.Email == user.Email).Count(); if (objUser == 0) { if (ModelState.IsValid) { db.Users.Add(user); db.SaveChanges(); base.SetFlashMessage("User has been successfully saved."); return(View()); } } else { ModelState.AddModelError("", "User Already Exists"); return(View(user)); } return(View(user)); }
private void btnEncrypt_Click(object sender, EventArgs e) { try { txtOutput.Text = EncrypterDecrypter.Encrypt(txtInput.Text, txtPassword.Text); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public IHttpActionResult GetUser(string email, string password) { password = EncrypterDecrypter.Encrypt(password); User user = db.Users.Where(d => d.Email == email && d.Password == password).FirstOrDefault(); if (user == null) { return(NotFound()); } return(Ok(user)); }
private void Encrypt_Clicked(object sender, EventArgs e) { try { entryOutput.Text = EncrypterDecrypter.Encrypt(entryInput.Text, entryPwd.Text); startTimer(); } catch (Exception ex) { DisplayAlert("Error:", ex.Message, "OK"); } }
public ActionResult Edit(User user) { if (ModelState.IsValid) { user.Password = EncrypterDecrypter.Encrypt(user.Password); user.UpdatedDate = DateTime.Now; db.Entry(user).State = EntityState.Modified; db.SaveChanges(); base.SetFlashMessage("User has been successfully saved."); return(RedirectToAction("Index")); } ViewBag.UserRoleID = new SelectList(db.UserRoles, "UserRoleID", "Role", user.UserRoleID); return(View(user)); }
public ActionResult Login(LoginViewModel model, string ReturnUrl) { if (!string.IsNullOrEmpty(model.Email) && !string.IsNullOrEmpty(model.Password)) { try { var password = EncrypterDecrypter.Encrypt(model.Password); var userObj = db.Users.Where(d => d.Email == model.Email && d.Password == password).FirstOrDefault(); if (userObj != null) { if (!userObj.IsActive) { ModelState.AddModelError("", "User account is Inactive"); return(View(model)); } FormsAuthentication.SetAuthCookie(userObj.Email, true); string URL = ""; if (string.IsNullOrEmpty(ReturnUrl)) { return(Redirect("~/Dashboard/Index")); } else { return(Redirect(ReturnUrl)); } } else { ModelState.AddModelError("", "Please enter correct email address or password"); return(View(model)); } } catch (Exception ex) { ModelState.AddModelError("", "Please enter correct email address or password"); return(View(model)); } } else { ViewBag.ReturnUrl = ReturnUrl; return(View(model)); } }
public ActionResult Create(User user) { user.CreatedDate = DateTime.Now; user.UpdatedDate = DateTime.Now; user.LinkExpiryDate = DateTime.Now; user.IsActive = true; user.CreatedBy = 1; user.UpdatedBy = 1; var objUser = db.Users.Where(d => d.Email == user.Email).Count(); if (objUser == 0) { if (ModelState.IsValid) { if (!user.UserRoleID.HasValue) { user.UserRoleID = 3; // HACK : default is User } user.Password = EncrypterDecrypter.Encrypt(user.Password); db.Users.Add(user); db.SaveChanges(); base.SetFlashMessage("User has been successfully saved."); return(RedirectToAction("Index")); } } else { ModelState.AddModelError("", "User Already Exists"); return(View(user)); } List <SelectListItem> rolesDropdown = new List <SelectListItem>(); foreach (var item in db.UserRoles) { rolesDropdown.Add(new SelectListItem { Value = item.UserRoleID.ToString(), Text = item.Role }); } ViewBag.UserRoleID = rolesDropdown; return(View(user)); }
public ActionResult ResetPassword(ResetPasswordViewModel model) { if (ModelState.IsValid) { var userObje = db.Users.Where(d => d.Email == model.Email).FirstOrDefault(); if (userObje != null) { userObje.Password = EncrypterDecrypter.Encrypt(model.Password); db.SaveChanges(); ViewBag.UpdateMessage = "Success"; return(View()); } } else { ModelState.AddModelError("", "Password & Confirm Password doesn't match"); return(View(model)); } return(View()); }