public Task <bool> Add(User newUserModel) { var currentDate = DateTime.UtcNow; try { //create salt and password hash var randomPass = EncryptionService.GenerateRandomPassword(8); var salt = EncryptionService.CreateRandomSalt(); var passwordHash = EncryptionService.HashPassword(randomPass, salt); newUserModel.PasswordHash = passwordHash; newUserModel.PasswordSalt = salt; newUserModel.CreatedDateUtc = currentDate; db.User.Add(newUserModel); db.SaveChanges(); return(Task.Run(() => true)); } catch { return(Task.Run(() => false)); } }
public bool ResetPassword(User user) { try { using (var db = new ClientManagementContext()) { var upateUser = db.Users.FirstOrDefault(d => d.Id == user.Id); if (upateUser == null) { return(false); } var randomPass = EncryptionService.GenerateRandomPassword(8); var salt = EncryptionService.CreateRandomSalt(); var passwordHash = EncryptionService.HashPassword(randomPass, salt); upateUser.PasswordHash = passwordHash; upateUser.PasswordSalt = salt; db.SaveChanges(); return(true); } } catch { return(false); } }
public Task <bool> ResetPassword(User user) { try { var updateUser = db.User.FirstOrDefault(d => d.Id == user.Id); if (updateUser == null) { return(Task.Run(() => false)); } var randomPass = EncryptionService.GenerateRandomPassword(8); var salt = EncryptionService.CreateRandomSalt(); var passwordHash = EncryptionService.HashPassword(randomPass, salt); updateUser.PasswordHash = passwordHash; updateUser.PasswordSalt = salt; db.SaveChanges(); return(Task.Run(() => true)); } catch { return(Task.Run(() => false)); } }
public bool Add(Contact contact) { try { using (var db = new ClientManagementContext()) { db.Contacts.Add(contact); db.SaveChanges(); var randomPass = EncryptionService.GenerateRandomPassword(8); var salt = EncryptionService.CreateRandomSalt(); var passwordHash = EncryptionService.HashPassword(randomPass, salt); var newUser = new User { ContactId = contact.Id, PasswordHash = passwordHash, PasswordSalt = salt, RoleId = UserRoleConstants.Customer, Username = contact.Username, Status = StatusConstants.Active, CreatedDateUtc = contact.CreatedDate }; db.Users.Add(newUser); db.SaveChanges(); return(true); } } catch (Exception ex) { return(false); } }