Example #1
0
        /// <summary>
        /// Verifies a user's credentials and returns the user's Id if successful, otherwise null.
        /// </summary>
        public override async Task <VerifyCredentialsResponse> VerifyCredentials(VerifyCredentialsRequest request, ServerCallContext context)
        {
            // Lookup the user by email address
            IEnumerable <UserCredentials> results = await _userCredentialsTable.Where(uc => uc.EmailAddress == request.Email)
                                                    .ExecuteAsync().ConfigureAwait(false);

            // Make sure we found a user
            UserCredentials credentials = results.SingleOrDefault();

            if (credentials == null || PasswordHash.ValidatePassword(request.Password, credentials.Password) == false)
            {
                var status = new Status(StatusCode.Unauthenticated, "Email address or password are not correct.");
                throw new RpcException(status);
            }

            return(new VerifyCredentialsResponse {
                UserId = credentials.UserId.ToUuid()
            });
        }
        /// <summary>
        /// Verifies a user's credentials and returns the user's Id if successful, otherwise null.
        /// </summary>
        public override async Task <VerifyCredentialsResponse> VerifyCredentials(VerifyCredentialsRequest request, ServerCallContext context)
        {
            PreparedStatement preparedStatement =
                await _statementCache.GetOrAddAsync("SELECT email, password, userid FROM user_credentials WHERE email = ?");

            // Use the get credentials prepared statement to find credentials for the user
            RowSet result = await _session.ExecuteAsync(preparedStatement.Bind(request.Email)).ConfigureAwait(false);

            // We should get a single credentials result or no results
            Row row = result.SingleOrDefault();

            if (row == null || PasswordHash.ValidatePassword(request.Password, row.GetValue <string>("password")) == false)
            {
                var status = new Status(StatusCode.Unauthenticated, "Email address or password are not correct.");
                throw new RpcException(status);
            }

            return(new VerifyCredentialsResponse {
                UserId = row.GetValue <Guid>("userid").ToUuid()
            });
        }