Ejemplo n.º 1
0
        public async Task <long> CreateUser(string username, string password, string email)
        {
            ValidateEmail(email);
            long createdAt    = DateTimeOffset.Now.ToUnixTimeMilliseconds();
            var  userIdentity = await UserAuthentication.GenerateUserCreds(username, password);

            Log.Info($"Creating new user [username={username} email={email}]");
            return(await UserDAO.Create(DbConnection, username, email, userIdentity.HashedPassword,
                                        userIdentity.Salt, userIdentity.HashingIterations, createdAt));
        }
Ejemplo n.º 2
0
        public async Task UpdateUserPassword(string username, string oldPassword, string newPassword)
        {
            if (!await ValidateUser(username, oldPassword))
            {
                throw new ArgumentException("Specified username/oldPassword is not correct.");
            }

            using (var transactionScope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
            {
                var    user       = (await UserDAO.GetByUserName(DbConnection, username)).Value;
                string resetToken = await UserDAO.GeneratePasswordResetToken(DbConnection, user.Id);

                var newUserIdentity = await UserAuthentication.GenerateUserCreds(username, newPassword);

                Log.Info(string.Format("Updating password for user " + username));
                await UserDAO.UpdatePassword(DbConnection, user.Id, resetToken, newUserIdentity.HashedPassword,
                                             newUserIdentity.Salt, newUserIdentity.HashingIterations);

                transactionScope.Complete();
            }
        }