/// <summary>
 /// The user currently logged in. 
 /// </summary>
 /// <returns>The user account of the user currently logged ins</returns>
 public UserAccount GetCurrentUser()
 {
     UserAccount user = CurrentUser;
     if (user == null)
     {
         user = GetUserAccountFromPrincipal();
         if (user != UserAccount.Anonymous)
             CurrentUser = user;
     }
     return user;
 }
 public UserAccount Create(Guid id, string name, string email, string password, string jobTitle)
 {
     if (id == null || id == Guid.Empty)
         throw new ArgumentException("An ID must be supplied to create a user");
     if (String.IsNullOrEmpty(password))
         throw new ArgumentException("A password must be supplied to create a user");
     var userAccount = new UserAccount
     {
         Id = id,
         EmailAddress = email,
         Name = name,
         JobTitle = jobTitle
     };
     SetPassword(userAccount, password);
     _userAccountValidator.ValidateThrowOnFailure(userAccount);
     _userAccountRepository.Create(userAccount);
     return userAccount;
 }
 private bool ValidatePassword(UserAccount userAccount, string password)
 {
     var hash = _cryptographicService.ComputeHash(password, userAccount.PasswordSalt);
     return hash == userAccount.PasswordHash;
 }
 private void SetPassword(UserAccount userAccount, string password)
 {
     userAccount.PasswordSalt = _cryptographicService.GenerateSalt();
     userAccount.PasswordHash = _cryptographicService.ComputeHash(password, userAccount.PasswordSalt);
 }