Пример #1
0
 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);
         }
     }
 }
Пример #2
0
 private static SaltedHash MapToHashedPassword(Account dbAccount)
 {
     return new SaltedHash(dbAccount.AccountPassword.PasswordHash.TrimEnd(), dbAccount.AccountPassword.Salt.TrimEnd());
 }
Пример #3
0
 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);
 }