public async Task <IActionResult> ResetPassword([FromBody] CreatePassword pwdModel) { try { var userMaster = await _context.UserMaster.FindAsync(pwdModel.UserId); GenericMethods.HashSalt hashSalt = GenericMethods.GenerateHashSalt(pwdModel.Password); userMaster.PasswordSalt = hashSalt.saltPassword; userMaster.PasswordHash = hashSalt.hashPassword; userMaster.LinkExpiryDate = DateTime.Now; _context.Entry(userMaster).State = EntityState.Modified; await _context.SaveChangesAsync(); GenericMethods.Log(LogType.ActivityLog.ToString(), "ResetPassword: "******"-Password created successfully"); } catch (Exception ex) { GenericMethods.Log(LogType.ErrorLog.ToString(), "ResetPassword: " + ex.ToString()); return(StatusCode(StatusCodes.Status500InternalServerError, ex)); } //catch (DbUpdateConcurrencyException) //{ // if (!UserMasterExists(id)) // { // return NotFound(); // } // else // { // throw; // } //} return(NoContent()); }
public async Task <PasswordChangeResult> Post(CreatePassword request) { var session = Request.ThrowIfUnauthorized(); var uid = session?.UserAuthId; if (uid == null) { throw new HttpError(HttpStatusCode.Unauthorized); } var user = await GetUserById(uid); if (user == null) { throw new HttpError(HttpStatusCode.NotFound); } var secret = await GetUserSecret(uid); if (secret.Password != null) { throw new HttpError(HttpStatusCode.Conflict); } secret.Password = request.NewPassword; await RavenSession.StoreAsync(secret); await RavenSession.SaveChangesAsync(); return(new PasswordChangeResult { Result = PasswordChangeResult.ChangeEnum.Created }); }
public async Task <UserDto> InsertUserAsync(UserDto userDto) { var newPassword = CreatePassword.CreateNewPassword(); await _context.AddAsync(new User() { FirstName = userDto.FirstName, LastName = userDto.LastName, Email = userDto.Email, RightId = userDto.RightId, PictureUrl = userDto.PictureUrl, Active = userDto.Active, CreatedAt = DateTime.Now, Password = CreatePassword.CreateHash(newPassword), Address = userDto.Address, UserFlag = 1 }); var checkInsert = await Complete(); if (!checkInsert) { return(null); } _logger.InsertDatabaseLog(new DataBaseLog() { Type = "Neuer User", Message = $"Neuer User {userDto.FirstName} {userDto.LastName} wurde hinzugefügt", CreatedAt = DateTime.Now }); await _serviceRepository.SendNewUserMailAsync(userDto, newPassword); return(userDto); }
public async Task <bool> SendNewPasswordMailAsync(User user) { var newPassword = CreatePassword.CreateNewPassword(); var hashPassword = CreatePassword.CreateHash(newPassword); var content = EmailService.CreateNewPasswordText(newPassword); var message = new Message() { Content = content, Subject = "Neues Password", EmailTo = user.Email, EmailFrom = _emailConfiguration.From, }; var emailMessage = EmailService.CreateEmailMessage(message); var checkMailSend = await SendAsync(emailMessage); if (!checkMailSend) { return(false); } var userToUpdate = await _context.Users.FindAsync(user.Id); userToUpdate.Password = hashPassword; userToUpdate.UserFlag = 1; await _context.SaveChangesAsync(); return(true); }
private void CreatePassword(IS2G10_DBSSSDataSet.USERPROFILERow userProfile) { _password = null; var createPasswordWindow = new CreatePassword(); if (createPasswordWindow.ShowDialog() == true) { _password = createPasswordWindow.Password; //values preserved after close } if (_password != null && !_password.Equals("")) { string hash; string salt; _passwordBuilder.CreateHash(_password, out hash, out salt); userProfile.resetPassword = false; userProfile.password_hash = hash; userProfile.password_salt = salt; _userProfileTableAdapter.Update(userProfile); _dialogService.CallMessageModal(this, "", SSS_Library.Properties.Resources.Login_CheckPassword_Password_Created_Successfully); } if (_password != null && _password.Equals("") || _password == null) { _dialogService.CallMessageModal(this, "", SSS_Library.Properties.Resources.Login_CheckPassword_Please_Enter_a_Password_); } }
public void CreatePassword(CreatePassword password) { DataSet applicationPasswordDataSet = new DataSet(); string userPassword = "******"; using (SqlConnection applicationPasswordConnection = new SqlConnection(ApplicationSettings.IDENTITY_CONNECTION_STRING)) { applicationPasswordConnection.Open(); string selectUserPassword = $"select * from {userPassword}"; using (SqlDataAdapter passwordAdapter = new SqlDataAdapter(selectUserPassword, applicationPasswordConnection)) { passwordAdapter.Fill(applicationPasswordDataSet, userPassword); SqlCommandBuilder userPasswordCommandBuilder = new SqlCommandBuilder(passwordAdapter); ApplicationUserPasswordHisroty uPassword = new ApplicationUserPasswordHisroty() { ApplicationUserId = Guid.NewGuid().ToString(), SetupDate = DateTime.Now.ToString("yyyy-MM-dd"), InvalidatedDate = DateTime.Now.AddDays(30).ToString("yyyy-MM-dd"), PasswordHash = password.PasswordHash }; passwordAdapter.SelectCommand = new SqlCommand(selectUserPassword, applicationPasswordConnection); userPasswordCommandBuilder = new SqlCommandBuilder(passwordAdapter); passwordAdapter.Fill(applicationPasswordDataSet, userPassword); var dataRow = applicationPasswordDataSet.Tables[userPassword].NewRowWithData(uPassword); applicationPasswordDataSet.Tables[userPassword].Rows.Add(dataRow); passwordAdapter.Update(applicationPasswordDataSet, userPassword); MessageBox.Show("Пароль добавлен"); } } }
public ActionResult CreatePassword(CreatePassword model) { ViewBag.Title = "Create Password"; UETCSEDbEntities db = new UETCSEDbEntities(); foreach (var person in db.AspNetUsers.ToList()) { if (person.Email == model.Email) { if (person.PasswordHash == null) { if (model.Password == model.ConfirmPassword) { person.PasswordHash = model.Password; db.AspNetUsers.Find(person.Id).PasswordHash = Encrypt.GetHash(model.Password); db.SaveChanges(); ViewBag.error = "Password Created"; return(View("Login")); } } else { //ViewBag.error = "Account has already created"; ModelState.AddModelError("Registration", "Account has already created"); break; } } } return(View()); }
public async Task <bool> SetPasswordAsync(CreatePassword model) { if (model == null || string.IsNullOrWhiteSpace(model.Password)) { return(false); } var sessionId = Context.GetSessionId(); if (!sessionInfoProvider.TryGet(sessionId, out var session)) { return(false); } var user = gameData.GetUser(session.AccountId); if (user == null) { return(false); } session.RequiresPasswordChange = false; user.PasswordHash = hasher.Get(model.Password); return(true); }
public async Task <bool> CheckValidRequst(string resetCode, string password) { var entity = await DbSet.SingleOrDefaultAsync(x => x.Code == resetCode); if (entity == null || entity.Code == "used") { return(false); } if (entity.WhenAskedForNew.AddMinutes(15) > DateTime.UtcNow && DateTime.UtcNow.AddMinutes(-15) < entity.WhenAskedForNew) { var user = await _userRepo.GetUser(entity.Email); CreatePassword.CreatePasswordHash(password, out byte[] hash, out byte[] salt); user.PasswordHash = hash; user.PasswordSalt = salt; //ownerEntry.RefreshToken = GetRefreshToken(); await _userRepo.UpdateUser(user); entity.Code = "used"; DbSet.Update(entity); await _dbContext.SaveChangesAsync(); return(true); } return(false); }
public void ChangePassword() { if (ExchangeManager.SettingsUnlocked()) { var createPassword = new CreatePassword(); createPassword.Closing += CreatePasswordOnClosing; createPassword.Show(); createPassword.Activate(); } }
public async Task <bool> ChangeUserPassword(ChangePasswordDto changePasswordDto) { var user = await _context.Users.FindAsync(changePasswordDto.UserId); if (user == null) { return(false); } user.Password = CreatePassword.CreateHash(changePasswordDto.Password); user.UserFlag = 0; return(await Complete()); }
public void LoadSettings() { if (ExchangeManager.SettingsAvailable()) { var login = new Login(); login.Closing += LoginOnClosing; login.Show(); login.Activate(); } else { var createPassword = new CreatePassword(); createPassword.Closing += CreatePasswordOnClosing; createPassword.Show(); createPassword.Activate(); } }
//Change Password - This should be accessable by every non disabled user. This may move to a new service. public bool ResetPassword(CreatePassword model) { PasswordHasher ph = new PasswordHasher(); ApplicationUser user = ctx.Users.Single(e => e.Id.ToString() == _userID.ToString()); user.PasswordHash = ph.HashPassword(model.Password); CreateHistory history = new CreateHistory { CompanyID = _companyID, UserID = _userID.ToString(), Table = "Users", stringID = null, Request = "ResetPassword(CreatePassword model)" }; AddHistory(history); return(ctx.SaveChanges() == 1); }
public User TransformDto(object obj) { var userRegistration = obj as UserRegistration; if (userRegistration == null) { return(null); } CreatePassword.CreatePasswordHash(userRegistration.Password, out byte[] hash, out byte[] salt); var dbUser = new User(); dbUser.PasswordHash = hash; dbUser.PasswordSalt = salt; dbUser.Email = userRegistration.Email; dbUser.Bio = userRegistration.Bio; dbUser.Username = userRegistration.FirstName; return(dbUser); }
public ActionResult CreatePassword(CreatePassword model) { DB50Entities db = new DB50Entities(); foreach (var person in db.Accounts.ToList()) { if (person.Email == model.Email) { if (model.NewPassword == model.ConfirmPassword) { person.Password = model.NewPassword; db.Accounts.Find(person.Id).Password = person.Password; db.SaveChanges(); return(RedirectToAction("Login", "Account")); } } } return(View()); }
static void Main() { //AccountService s = new AccountService(); //s.OpenOrganization(new ViewModels.OpenOrganizationViewModel() //{ // OrganizationIdentificationNumber = "2589645", // OrganizationFullName = "АО 'КТГ'", // OrganizationTypeId = 1, // CeoFirstName = "R", // CeoLastName = "L", // CeoMiddleName = "M", // Email = "*****@*****.**", // DoB = new DateTime(1986, 05, 12) //}); // PasswordService ps = new PasswordService(); //ps.CreatePassword(new ViewModels.CreatePassword() //{ // PasswordHash = "ааа" //}); CreatePassword cp = new CreatePassword() { Email = "*****@*****.**", oldPassword = "******", newPassword = "******", newPasswordConfirmation = "newqwerty" }; PasswordService p = new PasswordService(); p.ChangeUserPassword(cp); //s.GetGeolocationInfo(); //Application.EnableVisualStyles(); //Application.SetCompatibleTextRenderingDefault(false); //Application.Run(new Form1()); }
public async Task <ActionResult <AppUserDto> > Login(LoginDto loginDto) { var hashPassword = CreatePassword.CreateHash(loginDto.Password); var user = await _context.Users .AsNoTracking() .FirstOrDefaultAsync(u => u.Email == loginDto.Email && u.Password.Equals(hashPassword)); if (user == null) { return(BadRequest("E-Mail oder Passwort falsch")); } if (!user.Active) { return(BadRequest("Sie wurden von der Plattform gesperrt! Bitte wenden Sie sich an den Administrator")); } return(Ok(new AppUserDto() { UserId = user.Id, FullName = $"{user.FirstName} {user.LastName}", Email = user.Email, RightId = user.RightId, Token = _tokenService.CreateToken(user) })); }
public void ChangeUserPassword(CreatePassword passwordViewModel) { DataSet identityDataSet = new DataSet(); string userTable = "[dbo].[ApplicationUsers]"; string userPasswordTable = "[dbo].[ApplicationUserPasswordHistories]"; string userId = string.Empty; using (SqlConnection identityConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["IdentityDbConnectionString"].ConnectionString)) { identityConnection.Open(); string selectEmailPasswordSql = $"select u.Email, u.Id, p.SetupDate, p.PasswordHash " + $"from {userTable} u, {userPasswordTable} p " + $"where u.Id=p.ApplicationUserId and u.Email='{passwordViewModel.Email}'" + $"order by p.SetupDate desc"; using (SqlDataAdapter identityAdapter = new SqlDataAdapter(selectEmailPasswordSql, identityConnection)) { identityAdapter.Fill(identityDataSet); SqlCommandBuilder identityCommandBuilder = new SqlCommandBuilder(identityAdapter); DataTable dataTable = identityDataSet.Tables[0]; userId = dataTable.Rows[1][0].ToString(); int cnt = 0; if (dataTable.Rows.Count <= 5) { cnt = dataTable.Rows.Count; } else if (dataTable.Rows.Count > 5) { cnt = 5; } for (int i = 0; i < cnt; i++) { if (passwordViewModel.newPassword == dataTable.Rows[i][3].ToString()) { throw new ApplicationException($"{passwordViewModel.newPassword} уже был использован"); } } identityDataSet.Clear(); string selectUserPassword = $"select * from {userPasswordTable} " + $"where ApplicationUserId = '{userId}' " + $"and InvalidatedDate is null"; identityAdapter.SelectCommand = new SqlCommand(selectUserPassword, identityConnection); identityCommandBuilder = new SqlCommandBuilder(identityAdapter); identityAdapter.Fill(identityDataSet); DataTable table = identityDataSet.Tables[0]; table.Rows[1]["InvalidatedDate"] = DateTime.Now.ToString("yyyy-MM-dd"); identityAdapter.Update(identityDataSet); identityDataSet.Clear(); ApplicationUserPasswordHisroty userPassword = new ApplicationUserPasswordHisroty() { Id = 8, ApplicationUserId = userId, SetupDate = DateTime.Now.ToString("yyyy-MM-dd"), PasswordHash = passwordViewModel.newPassword }; string userPasswordSql = $"select * from {userPasswordTable}"; identityAdapter.SelectCommand = new SqlCommand(userPasswordSql, identityConnection); identityCommandBuilder = new SqlCommandBuilder(identityAdapter); identityAdapter.Fill(identityDataSet, userPasswordTable); var dataRow = identityDataSet.Tables[userPasswordTable].NewRowWithData(userPassword); identityDataSet.Tables[userPasswordTable].Rows.Add(dataRow); identityAdapter.Update(identityDataSet, userPasswordTable); } } }
public async Task <ActionResult> CreatePassword(CreatePassword model) { if (ModelState.IsValid) { //Create new User and Account var user = new CommonUser(); user.Email = model.InvitedEmail; user.FirstName = model.FirstName; user.LastName = model.LastName; user.Permission = model.SystemPermission; user.SetPassword(model.Password); //Check Account var commonAccount = await CommonContext.CommonAccounts.Where(m => m.Id == model.AccountId).SingleOrDefaultAsync(); var vendorDetail = await _accountCtx.Vendors.Where(x => x.Id == model.VendorId).SingleOrDefaultAsync(); if (commonAccount == null) { ViewBag.SucessMessage = "Account not found"; return(View(model)); } CommonUserAccount userAccount = new CommonUserAccount(); userAccount.CreateUserId = commonAccount.OwnerUserId.Value; userAccount.AccountId = commonAccount.Id; userAccount.UpdateUserId = commonAccount.OwnerUserId.Value; userAccount.UserId = user.Id; userAccount.Permissions = (AccountPermissions)model.Permission; if (vendorDetail != null) { user.Permission = SystemPermissions.Vendor; } using (var tx = CommonContext.Database.BeginTransaction()) { CommonContext.Users.Add(user); await CommonContext.SaveChangesAsync(); CommonContext.UserAccounts.Add(userAccount); await CommonContext.SaveChangesAsync(); tx.Commit(); } //Create AccountUser var accountUser = new AccountUser { Id = userAccount.UserId.Value, FirstName = user.FirstName, LastName = user.LastName, Email = user.Email }; _accountCtx.AccountUsers.Add(accountUser); if (vendorDetail != null) { AccountUserVendor accountUserVendor = new AccountUserVendor(); accountUserVendor.VendorId = vendorDetail.Id; accountUserVendor.AccountUserId = accountUser.Id; _accountCtx.AccountUserVendors.Add(accountUserVendor); } await _accountCtx.SaveChangesAsync(); await SignInUser(user, false); return(RedirectToAction("Index", "Accounts")); } return(View(model)); }