Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7801839
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T01:04:12+00:00 2026-06-02T01:04:12+00:00

Looking for some feedback on querying for a user when authenticating. The first thought

  • 0

Looking for some feedback on querying for a user when authenticating. The first thought i had when writing the code below was to get the username by querying all usernames in the database and checking if the username provided belongs to a list of users. Would this type of checking become a performance issue when the users table grows?

    EntityManager entityManager = factory.createEntityManager();
    /*Create a data structure to hold a list of users in our database*/
    List<String> allUsernames = new ArrayList<String>();  

    allUsernames = entityManager.createQuery("SELECT user.username FROM Users user").getResultList();

    /*Loop through each user in our available usernames checking if the username passed exists*/
    for (String user : allUsernames) {

        if (user.equals(username)) {
            System.out.println("Found real user\n");
            userFoundFLAG = 1; // set the flag equal to 1 when this user is found
        }

    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T01:04:13+00:00Added an answer on June 2, 2026 at 1:04 am

    Why don’t you just query for the user by name? If a non-zero list is returned then the user exists, else it doesn’t. Even better, why not just read the entire user object since, conceivably, you will need it for additional authentication/authorization logic?

    final TypedQuery<String> query = entityManager
          .createQuery("SELECT u.username FROM Users u WHERE u.username = :username", String.class);
    query.setParameter("username", "BillyBob");
    if (query.getResultList().size() > 0) {
       // ...
    }
    

    Or:

    final TypedQuery<User> query = entityManager
          .createQuery("SELECT u FROM Users u WHERE u.username = :username");
    query.setParameter("username", "BillyBob");
    final User user = query.getFirstResult();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am looking to get some feedback on how I can improve my design.
I'm looking for some feedback from anyone that has had a chance to spend
We have a SaaS web app and are looking to get some feedback from
I’m looking for some feedback on mechanisms to batch data from MySQL Community Server
Looking for some help with optimising the query below. Seems to be two bottlenecks
I'm looking for some feedback on the advantages and disadvantages of the methods available
I am looking for some general feedback here. I have a very simple application
Strange one here, hoping to get some feedback to point me in the right
Looking for some feedback on setting up our solutions in TFS. Right now we
I wanted to get some info/tips on making a Generic (iOS/Android/WebOS/etc...) Mobile Site. Looking

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.