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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:52:04+00:00 2026-05-27T21:52:04+00:00

I am trying to read a pasword and while I read it , display

  • 0

I am trying to read a pasword and while I read it , display ** .

    cout << "\n Insert password : ";
loop1:
    string passw1 = "";
    char ch = _getch();
    while (ch != 13) // enter = char 13
    {
        if (!isalnum(ch))
        {
            cout << "\n\n Invalid character! Please insert the password again! ";
            goto loop1;
        }

        passw1.push_back(ch);
        cout << "*";
        ch = _getch();
    }

If I press for example , BACKSPACE , or SPACE or something that is not alpha-numerical , everything goes as planned. The problem is when I press any F key , or DELETE , HOME , INSERT , END , PG UP , PG DOWN , when the program crashes . Could you help me avoid the crash ? I would like to show an error message if an invalid key is pressed , not to have my program crash.

  • 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-27T21:52:05+00:00Added an answer on May 27, 2026 at 9:52 pm

    Use the is alphanumeric function – isalnum(char c ) to check if the parameter c is either a decimal digit
    or an uppercase or a lowercase letter.

    And then filter out characters less than 32 or higher than 122 like this : if (c > 32 && c <122) { Get_Password(); }

    This MS Windows specific code below is not portable. For Linux/*NIX/BSD see this : Hide password input on terminal

    #include <iostream>
    #include <string>
    #include <conio.h>
    
    int main()
    {
        std::string password;
        char ch;
        const char ENTER = 13;
    
        std::cout << "enter the password:  ";
    
        while((ch = _getch()) != ENTER)
        {
    
            if (ch > 32 && ch<122)
            {
                if (isalnum(ch))
                {
                    password += ch;
                    std::cout << '*';
    
                }
    
            }
        }
        std::cout <<"\nYour password is : " << password<<"\n\n";
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

While trying to connect to a database that's set to read only, the connection
I am trying to read a UTF-8 string from my MySql database, which I
Trying to read an RSS and select information using Linq but can't seem to
Trying to read headers for a csv file with: reader = csv.DictReader(open(PATH_FILE),skipinitialspace=True) headers =
I'm currently trying to read in an XML file, make some minor changes (alter
I'm trying to read through the documentation on Berkeley DB XML , and I
I'm trying to read a .doc file into a database so that I can
I am trying to read a single file from a java.util.zip.ZipInputStream , and copy
I am trying to read ASCII text response from a tcp open streaming socket
I am trying to read an Http response stream twice via the following: HttpWebResponse

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.