public IActionResult ChangePassword([FromBody] ChangePasswordDTO changePasswordDTO) { try { int userId = (int)this.HttpContext.Items["userId"]; User userToChangeHisPassword = _eyadtakDbContext.Users.FirstOrDefault(x => x.UserId == userId); userToChangeHisPassword.Password = Encription.Decrypt(userToChangeHisPassword.Password, "SecretCode_hamed"); if (userToChangeHisPassword.Password != changePasswordDTO.OldPassword) { return(Ok(new { message = "Old password is wrong", ErrorHappen = true })); } if (changePasswordDTO.NewPassword.Length < 5) { return(Ok(new { message = "New password can't be less than 5 char", ErrorHappen = true })); } userToChangeHisPassword.Password = Encription.Encrypt(changePasswordDTO.NewPassword, "SecretCode_hamed"); _eyadtakDbContext.Users.Update(userToChangeHisPassword); _eyadtakDbContext.SaveChanges(); return(Ok(new { message = "Password Changed Successfully", ErrorHappen = false })); } catch (Exception e) { return(Ok(new { message = "Something went wrong", ErrorHappen = true })); throw e; } }
public Task <bool> Handle(AlterarUsuarioCommand message, CancellationToken cancellationToken) { #region Basic Validations if (!message.IsValid()) { NotifyValidationErrors(message); return(Task.FromResult(false)); } #endregion var password = Encription.Encrypt(message.Password, Encription.Key256, 256); var usuario = new Usuario( message.Id, message.Nome, message.Idade, message.Documento, message.TipoDocumento, message.Genero, message.Pai, message.Mae, message.Telefone, message.Celular, message.Email, password, message.UsuarioId ); _usuarioRepository.Update(usuario); if (Commit()) { _bus.RaiseEvent(new AlterarUsuarioEvent()); } return(Task.FromResult(true)); }
public UsuarioViewModel ObterUsuario(UsuarioAuthenticateViewModel vm) { vm.Password = Encription.Encrypt(vm.Password, Encription.Key256, 256); var usuario = _usuarioRepository.ObterPorEmailPassword(vm.Email, vm.Password); return(_mapper.Map <UsuarioViewModel>(usuario)); }
public IActionResult Login([Bind("UserName", "Password")] Account account) { Encription encription = new Encription(); bool existed = _context.Account.Any(x => x.UserName.TrimEnd().ToLower().Equals(account.UserName.TrimEnd().ToLower()) && x.Password.Equals(account.Password)); if (existed) { Account selectedAccount = _context.Account.Where(x => x.UserName.TrimEnd().ToLower().Equals(account.UserName.TrimEnd().ToLower()) && x.Password.Equals(account.Password)).FirstOrDefault(); int? AccountTypeId = selectedAccount.AccountTypeId; ApplicationKeys appKeys = new ApplicationKeys(); string UserNameEncription = encription.Encrypt(appKeys.Key_UserName, selectedAccount.UserName); string PasswordEncription = encription.Encrypt(appKeys.Key_Password, selectedAccount.Password); //HttpContext.Session.SetString("x", UserNameEncription); //HttpContext.Session.SetString("y", PasswordEncription); _session.SetString("x", UserNameEncription); _session.SetString("y", PasswordEncription); if (AccountTypeId == AccountType_Doctor) { ViewData["Layout"] = "_DoctorLayout"; //ViewData["ContactLayout"] = "~/Views/Shared/_DoctorLayout.cshtml"; return(RedirectToAction("DoctorDefault", "Home", new { id = UserNameEncription, y = PasswordEncription })); } else if (AccountTypeId == AccountType_Admin) { ViewData["Layout"] = "_AdminLayout"; //ViewData["ContactLayout"] = "~/Views/Shared/_AdminLayout.cshtml"; return(RedirectToAction("AdminDefault", "Home", new { id = UserNameEncription, y = PasswordEncription })); } else if (AccountTypeId == AccountType_Patient) { ViewData["Layout"] = "_PatientLayout"; //ViewData["ContactLayout"] = "~/Views/Shared/_PatientLayout.cshtml"; return(RedirectToAction("PatientDefault", "Home", new { id = UserNameEncription, y = PasswordEncription })); } else { return(RedirectToAction("Login")); } } else { return(RedirectToAction("Login")); } }
/// <summary> /// Encodes a visible string. /// </summary> /// <param name="source">The string to encode.</param> /// <returns>The encoded string.</returns> private static string Encode(string source) { var result = string.Empty; if (!string.IsNullOrEmpty(source) && !string.IsNullOrWhiteSpace(source)) { var encription = new Encription(); result = encription.Encrypt(source); } return(result); }
public IActionResult Register([FromBody] UserRegisterDTO userRegisterDto) { try { if (userRegisterDto.Password.Length < 5) { return(Ok(new { message = "Password can't be less than 5 char", ErrorHappen = true })); } User userObj = _eyadtakDbContext.Users.FirstOrDefault(x => x.UserEmail == userRegisterDto.Email); if (userObj != null) { return(Ok(new { message = "This Email Already Exsist", ErrorHappen = true })); } User user = new User() { Password = Encription.Encrypt(userRegisterDto.Password, "SecretCode_hamed"), UserName = userRegisterDto.Name, UserEmail = userRegisterDto.Email, Active = false, RegisterDate = DateTime.Now, RecoveryCode = -1, GenderId = userRegisterDto.GenderId, PhoneNumber = userRegisterDto.PhoneNumber }; user.User_Role = new List <User_Role>(); user.User_Role.Add(new User_Role() { RoleId = userRegisterDto.RoleId, UserId = user.UserId }); _eyadtakDbContext.Users.Add(user); _eyadtakDbContext.SaveChanges(); string token = _jwt.GenerateToken(user.UserId); _email.SendAccountActivationEmail(user.UserEmail, _configuration.GetSection("Frontend:Url").Value + "/account/activate-account/?token=" + token); return(Ok(new { message = "User Registerd Successfully", ErrorHappen = false })); } catch (Exception e) { return(Ok(new { message = e.Message, ErrorHappen = true })); throw e; } }
public Result SelfPasswordChange(ChangePasswordModel changePassword) { try { result = new Result(); result.isSucess = false; Dictionary <int, CheckSessionData> dictionary = CheckSessionData.GetSessionValues(); int userGroupId = Convert.ToInt32(dictionary[6].Id == "" ? 0 : Convert.ToInt32(dictionary[6].Id)); if (userGroupId != 0) { int userId = Convert.ToInt32(dictionary[3].Id); string userName = dictionary[4].Id; _userFactory = new UserFactory(); bool status = _userFactory.GetAll().Any(x => x.UserName == userName && x.UserGroupID == userGroupId); if (status == true) { SEC_UserInformation tblUserInformation; tblUserInformation = _userFactory.FindBy(x => x.ID == userId).FirstOrDefault(); _passwordFactory = new UserPasswordFactory(); Encription encription = new Encription(); SEC_Password tblPassword = _passwordFactory.GetAll().FirstOrDefault(x => x.ID == tblUserInformation.PasswordID); if (tblPassword != null) { tblPassword.OldPassword = tblPassword.NewPassword; tblPassword.NewPassword = encription.Encrypt(changePassword.NewPassword.Trim()); tblPassword.IsSelfChanged = true; tblPassword.UpdatedDate = DateTime.Now; tblPassword.UpdatedBy = userId; _passwordFactory.Edit(tblPassword); } result = _passwordFactory.Save(); if (result.isSucess) { result.message = "Changed Password Sucessfully"; return(result); } } result.message = "Password not Changed try again"; return(result); } result.message = "LogOut"; } catch (Exception exception) { result.isSucess = false; result.message = exception.Message; } return(result); }
public RegistrarNovoUsuarioCommand(Guid usuarioId, string nome, int idade, TipoDocumento tipoDocumento, string documento, Genero genero, string pai, string mae, long telefone, long celular, string email, string password, IEnumerable <Guid>?appsId = null) { UsuarioId = usuarioId; Nome = nome; Idade = idade; Documento = documento; TipoDocumento = tipoDocumento; Genero = genero; Pai = pai; Mae = mae; Telefone = telefone; Celular = celular; Email = email; Password = Encription.Encrypt(password, Encription.Key256, 256); AppsId = appsId; }
public ActionResult ChangePassword([FromBody] ChangePasswordDto changePasswordDto) { User user = userData.GetUser(HttpContext); user.Password = Encription.Decrypt(user.Password, "SecretCode_hamed"); if (user.Password != changePasswordDto.OldPassword) { return(Json(new { statusCode = ResponseStatus.ValidationError, responseMessage = ValidationMessages.IncorrectPassword })); } if (changePasswordDto.NewPassword.Length < 5) { return(Json(new { statusCode = ResponseStatus.ValidationError, responseMessage = ValidationMessages.ShortPassword })); } user.Password = Encription.Encrypt(changePasswordDto.NewPassword, "SecretCode_hamed"); db.Users.Update(user); db.SaveChanges(); userData.SetUser(HttpContext, user); return(Json(new { statusCode = ResponseStatus.Success })); }
public IActionResult Register([FromBody] UserRegisterDTO userRegisterDto) { User user = UserMapper.Map(userRegisterDto); FillEmptyFields(user); UserValidator validator = new UserValidator(ValidationMode.Create, db); var result = validator.Validate(user); if (!result.IsValid) { return(Json(new { statusCode = ResponseStatus.ValidationError, responseMessage = result.Errors })); } user.Password = Encription.Encrypt(user.Password, "SecretCode_hamed"); db.Add(user); db.SaveChanges(); string token = jwt.GenerateToken(user.Id); email.SendAccountActivationEmail(user.Email, "https://localhost:44340/Account/ActivateAccount/?token=" + token); return(Json(new { statusCode = ResponseStatus.Success, responseMessage = user.Id })); }
public ActionResult RecoverPassword([FromBody] RecoverPasswordDTO recoverPasswordDTO) { User user = _eyadtakDbContext.Users.FirstOrDefault(s => s.UserEmail == recoverPasswordDTO.UserEmail); if (user == null) { return(Ok(new { message = "This Email does not Exsist", ErrorHappen = true })); } if (user.RecoveryCode != recoverPasswordDTO.RecoveryCode) { return(Ok(new { message = "This Code is not Correct", ErrorHappen = true })); } if (recoverPasswordDTO.NewPassword.Length < 5) { return(Ok(new { message = "Password Lenght can't be less than 5 char", ErrorHappen = true })); } user.Password = Encription.Encrypt(recoverPasswordDTO.NewPassword, "SecretCode_hamed"); user.RecoveryCode = -1; _eyadtakDbContext.Update(user); _eyadtakDbContext.SaveChanges(); return(Ok(new { message = "Password Changed Successfully", ErrorHappen = false })); }
public ActionResult RecoverPassword([FromBody] UserLoginDTO userLoginDTO, [FromQuery] string code) { User user = db.Users.Include(x => x.ProfilePhotos).Where(s => s.Email == userLoginDTO.Email && s.IsDeleted == false).FirstOrDefault(); if (user == null) { return(Json(new { statusCode = ResponseStatus.ValidationError, responseMessage = ValidationMessages.EmailNotExsist })); } if (user.RecoveryCode.ToString() != code) { return(Json(new { statusCode = ResponseStatus.ValidationError, responseMessage = ValidationMessages.WrongCode })); } if (userLoginDTO.Password.Length < 5) { return(Json(new { statusCode = ResponseStatus.ValidationError, responseMessage = ValidationMessages.ShortPassword })); } user.Password = Encription.Encrypt(userLoginDTO.Password, "SecretCode_hamed"); user.RecoveryCode = null; db.Update(user); db.SaveChanges(); userData.SetUser(HttpContext, user); return(Json(new { statusCode = ResponseStatus.Success })); }
public IActionResult GetEncryptPassword(string password) { return(Ok(Encription.Encrypt(password))); }
private JsonResult CreateUser(UserModel user, int userId) { result = new Result(); _questionFactory = new QuestionFactory(); _passwordFactory = new UserPasswordFactory(); var question = new SEC_SecurityQuestion(); question.ID = Guid.NewGuid(); question.SecurityQuestion = user.SecurityQuestion; question.SecutiryAnswer = user.SecurityQueAns; question.CreatedBy = userId; question.CreatedDate = DateTime.Now; _questionFactory.Add(question); result = _questionFactory.Save(); var password = new SEC_Password(); if (result.isSucess) { var encription = new Encription(); password.ID = Guid.NewGuid(); password.NewPassword = encription.Encrypt(user.Password); password.OldPassword = ""; password.IsSelfChanged = false; password.CreatedBy = userId; password.CreatedDate = DateTime.Now; _passwordFactory.Add(password); result = _passwordFactory.Save(); } var userInformation = new SEC_UserInformation(); //userInformation.ID = Guid.NewGuid(); if (result.isSucess) { userInformation.EmployeeID = user.EmployeeID; userInformation.CompanyID = user.CompanyID; userInformation.BranchID = user.BranchID; userInformation.UserFullName = user.UserFullName; userInformation.UserName = user.UserName.ToLower().Trim(); userInformation.Address = user.Address; userInformation.Email = user.EMail; userInformation.PhoneNo = user.PhoneNo; userInformation.SecurityQuestionID = question.ID; userInformation.PasswordID = password.ID; userInformation.IsEMailVerified = false; userInformation.IsPhoneNoVerified = false; userInformation.IsActive = true; userInformation.CreatedBy = userId; userInformation.CreatedDate = DateTime.Now; userInformation.UserGroupID = user.UserGroupID; _userFactory.Add(userInformation); result = _userFactory.Save(); } if (result.isSucess) { result.message = result.SaveSuccessfull(tableName); return(Json(result, JsonRequestBehavior.AllowGet)); } else { return(Json(result, JsonRequestBehavior.AllowGet)); } }
public Result PasswordChangeByAdminSave(ChangePasswordModel changePassword) { try { result = new Result(); result.isSucess = false; Dictionary <int, CheckSessionData> dictionary = CheckSessionData.GetSessionValues(); int userGroupID = Convert.ToInt32(dictionary[6].Id); int userId = Convert.ToInt32(dictionary[3].Id); string userName = dictionary[4].Id; if (userGroupID != 0) { _userFactory = new UserFactory(); _passwordFactory = new UserPasswordFactory(); _userGroup = new UserGroupFactory(); Encription encription = new Encription(); SEC_Password tblPassword; SEC_UserInformation tblUserInformation = new SEC_UserInformation(); SEC_UserGroup tblUserGroup = new SEC_UserGroup(); if (changePassword.FullName != "" || changePassword.UserName != "") { if (changePassword.UserName != null) { tblUserInformation = _userFactory.FindBy(x => x.UserName == changePassword.UserName).FirstOrDefault(); } tblUserGroup = _userGroup.FindBy(x => x.ID == userGroupID).FirstOrDefault(); if (tblUserGroup != null) { if (tblUserGroup.IsAdmin == false) { result.message = "You are not a Admin"; return(result); } tblPassword = _passwordFactory.GetAll().FirstOrDefault(x => x.ID == tblUserInformation.PasswordID); if (tblPassword != null) { tblPassword.OldPassword = tblPassword.NewPassword; tblPassword.NewPassword = encription.Encrypt(changePassword.NewPassword.Trim()); tblPassword.IsSelfChanged = false; tblPassword.UpdatedDate = DateTime.Now; tblPassword.UpdatedBy = userId; _passwordFactory.Edit(tblPassword); } result = _passwordFactory.Save(); if (result.isSucess) { result.message = "Changed Password Sucessfully"; return(result); } } result.message = "User cant found"; return(result); } result.message = "Password not Changed try again"; return(result); } result.message = "Logout"; } catch (Exception exception) { result.isSucess = false; result.message = exception.Message; return(result); } return(result); }