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 6803993
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:24:43+00:00 2026-05-26T19:24:43+00:00

I am creating a login menu in C++ i wish to give the user

  • 0

I am creating a login menu in C++

i wish to give the user 3 attempts at entering the password before the program terminates.

My code runs fine if the user gets the password right the first time. It would then go into the home menu ect. However, if the user gets the password wrong. The terminal would run up to:

Login: Fred
Password: ***
Wrong password
Please re-enter password: 

After which point nothing would show up regardless of what the user types. Not even ctrl-C can exit the program. I was wondering if anyone know what’s going on and can point me in the right direction.

Here’s part of the codes for the method “login” in a class called “HomePage”:

            cout<<"Password: ";

            while (loginAttempt < 3){                                       //The user gets to attempt to type
                                                                            //the password 3 times
                    password = receivePassword();                           //Receives password from user


                    if (flatMemberList[match].getPassword()==password){     //Check if the password is correct
                        cout<<endl<<"Welcome back "<<loginName<< endl;      //If correct, display welcome message
                        return;
                    }

                    else{
                       loginAttempt++;                                      //Record down one failed attempt
                       cout<<endl<<"Wrong password"<<endl;                  //If incorrect, display error
                       cout<<"Please re-enter password: ";
                    }
            }
            cout<<"you have exceeded the legal login attempts"<<endl;
            exit(1);

Where receivePassword() is a custom method as follows:

//This method is called when the user types in a password
//The terminal's setting is first changed to 'raw' configuration
//The password are taken in one letter at a time
//It outputs to terminal "*" instead of echoing the input
string HomePage::receivePassword(){

        termios oldt, newt;                                     //The structs for manipulation
        char password[PaswordLength];                           //Password held here
        int j = 0;                                              //Password index

        tcgetattr(STDIN_FILENO, &oldt);                         //Get configuration details
        newt = oldt;
        cfmakeraw(&newt);                                       //Set up new 'raw' configuration structure

    //Set up new terminal configuration

        tcsetattr(STDIN_FILENO, TCSANOW, &newt);

        cin.ignore(1000, '\n');                                 //flush all the buffers

        while(true){
            password[j] = cin.get();            
            if( password[j] == '\r' ) {                         //check if 'enter' key is entered
                password[j] = '\0';                             //replace cr with null to make C string
                break;
            }
            cout.put('*'); //echo the asterisk

            j++;
        } ;

    //Reset terminal to old configuration

        tcsetattr(STDIN_FILENO, TCSANOW, &oldt);

        return password;
    }

Thanks in advance

If you think the problem might be elsewhere, let me know, and i’ll post the codes.

  • 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-05-26T19:24:44+00:00Added an answer on May 26, 2026 at 7:24 pm

    I don’t know what your specific problem is. However, you can apply standard debugging techniques to find out which part is causing the problem.

    First, you’re doing weird things with terminals (cfmakeraw, tcsetattr, etc). It sounds like that might be related to the problem. So, remove the code that hides the user input and make sure your program works when the password is echoed to the screen normally. You should be able to do that easily.

    After doing this, you can then decide whether your problem is related to:

    • the terminal attribute code that you removed, or
    • the password loop that remains.

    This is often called the “divide and conquer” debugging technique. If you remove the code that you think is the problem, then whether the problem remains or not can help you decide whether it’s related to the code you removed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating a login page and want to give user the flexibility to
Im creating a login page. Below code is when user fills in both username
So I'm creating a site where users must login. If the user wishes that
I am creating login pages using asp.net with code behind in vb.net, I am
I'm currently creating a Login form and have this code: string connectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
i am creating login code for facebook connect on our site, however i cannot
i am creating login in my app. User type his info i send it
So I'm creating a login form.Validating user input to check whether the email format
We are new to ROR, We have issue in creating Login/Logout process in ROR
I am creating a login system for a web application using PHP. My question

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.