i have a program, which uses a password inputation but when i made the password encrypted. when inputting my password which now appear as star(***) due to encryption. trying to delete a character but backspace is being read as a character. please can someone show me the way forward... thanks

cout << "Password: ";
encrypt = _getch();
while(encrypt != 13)

{
Password.push_back(encrypt);
cout << '*';
encrypt = _getch();

Recommended Answers

All 7 Replies

You have to do that work yourself now, because you've sidestepped the shell and taken over its job. Now it's your job:

#include <iostream>
#include <string>
#include <conio.h>

std::string get_password()
{
    std::string password;
    int ch;

    while ( ( ch = getch() ) != '\r' ) {
        if ( ch == '\b' ) {
            // Process a destructive backspace
            if ( password.size() > 0 ) {
                password.erase( password.size() - 1, 1 );
                std::cout<<"\b \b";
            }
        }
        else {
            password.push_back( ch );
            std::cout.put ( '*' );
        }
    }

    std::cout.put ( '\n' );

    return password;
}

int main()
{
    std::cout<<'('<< get_password() <<")\n";
}

please, if i could send you my code, is there anyway u would be able to help me. thanks for your response...

actually that is pretty cool that your program is seeing a backspace as a character. what better protection than allowing a backspace as part of your password. you may have just come up with a stronger security system.

>>please, if i could send you my code, is there anyway u would be able to help me. thanks for your response...
What the ____?
Narue has already given you the standard c++ code. What else you can expect as 'help'.


>>what better protection than allowing a backspace as part of your password. you may have just come up with a stronger security system.
I disagree. There is thin line between comfortability and security. If I was a user, and I knew that I could not use backspace to erase the last mis-typed character I entered, I would count the software as non-user-friendly

>>please, if i could send you my code, is there anyway u would be able to help me. thanks for your response...
What the ____?
Narue has already given you the standard c++ code. What else you can expect as 'help'.


>>what better protection than allowing a backspace as part of your password. you may have just come up with a stronger security system.
I disagree. There is thin line between comfortability and security. If I was a user, and I knew that I could not use backspace to erase the last mis-typed character I entered, I would count the software as non-user-friendly

Sorry about that, I was just kidding. As a network manager I get asked a lot of questions including those about secure passwords, and as I watch some users type in their password and forget part of them and hit backspace, I kid around as backspace being part of the password. Also we all know the best password is ****************

>>Also we all know the best password is ****************
I doubt it. Best password? When I type this password in the Google Signup page, it tells me the password strength is "Fair".
Also, if there was a "Best" Password, most people will try to keep it. And thus it becomes a worst password.

If you were kidding, I am really laughing, and my stomach is aching.

>>Also we all know the best password is ****************
I doubt it. Best password? When I type this password in the Google Signup page, it tells me the password strength is "Fair".
Also, if there was a "Best" Password, most people will try to keep it. And thus it becomes a worst password.

If you were kidding, I am really laughing, and my stomach is aching.

yep just kidding again on the **************** thing. in other words everyone's password is some form of a bunch of ****'s from a stander by's viewpoint. who knows what is really behind all those *'s ? maybe even a backspace ;-)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.