Exemple #1
0
        public void CreateLogin(TUser user, string loginUsername, string password)
        {
            if (!_userNameValidator.IsValid(loginUsername))
            {
                throw new InvalidDataException("LoginUsername was not provided in the expected format");
            }
            // Generate a random salt for this user
            var salt  = GetRandomSalt();
            var login = new TLogin
            {
                LoginUsername = loginUsername,
                Salt          = salt,
                Hash          = GetHash(salt, password),
                User          = user
            };

            _authDb.Add <TLogin>(login);
            _authDb.Save();
        }
Exemple #2
0
        public T CreateUser(string primaryEmailAddress)
        {
            if (!_emailAddressValidator.IsValid(primaryEmailAddress))
            {
                throw new InvalidDataException("Unable to CreateUser, Email address was not in expected format.");
            }

            if (_authDb.ModelPresent <T>() && _authDb.Query <T>().Any(p => p.PrimaryEmailAddress.Equals(primaryEmailAddress)))
            {
                throw new DuplicateAccountException();
            }

            var user = new T
            {
                PrimaryEmailAddress = primaryEmailAddress
            };

            _authDb.Add <T>(user);
            _authDb.Save();
            return(user);
        }