public void CreateAccount(AccountManagement.Account account, SaltedHash passwordHash, UserId userId) { Contract.Assert(account.AccountId.IsNew); using (var db = new THCard()) { using (var transaction = new TransactionScope()) { var dbAccount = new Account { Username = account.Username.ToString(), UserId = userId.ToGuid(), AccountPassword = new AccountPassword { PasswordHash = passwordHash.Hash, Salt = passwordHash.Salt } }; db.Accounts.Add(dbAccount); db.SaveChanges(); transaction.Complete(); account.AccountId = new AccountId(dbAccount.AccountId); } } }
private static SaltedHash MapToHashedPassword(Account dbAccount) { return new SaltedHash(dbAccount.AccountPassword.PasswordHash.TrimEnd(), dbAccount.AccountPassword.Salt.TrimEnd()); }
private static AccountManagement.Account MapAccount(Account dbAccount) { var roles = new AccountRoles(dbAccount.Roles.Select(BuildRoleFromDBRole)); return new AccountManagement.Account(new AccountId(dbAccount.AccountId), new Username(dbAccount.Username), roles); }