What is the Best Way to Create a Secure Password Prompt in C++?

  • Comp Sci
  • Thread starter Deathfish
  • Start date
  • Tags
    C++ Echo
In summary, The person is using stdio.h, conio.h, string.h, stdlib.h to create a password prompt that echoes asterisks for each character. They also want to allow for backspacing and deleting while creating the password and store it in an array that can hold up to 100 passwords. The output indentation may look bad and they recommend using input filtering to ensure only desired characters are accepted. It is also suggested to have the user type the password twice for verification.
  • #1
Deathfish
86
0
Homework Statement

Currently using stdio.h, conio.h, string.h, stdlib.h
not using iostream, namespace std etc.

I am asked to make a password prompt where each character echoes an asterisk (*)

The user must be able to backspace and delete to make corrections.

The password is then stored in an array which can accommodate up to 100 passwords.

The attempt at a solution

count=0;
while(c != eof())
{
`c=getch();
if (c != eof())
{
printf("*");
c=pw[userid][count];
count++;
}
}
pw[userid][count] = '\0';

sadly, the output indentation looks horrible and it is uneditable using backspace and delete.
 
Physics news on Phys.org
  • #2
As I recall, getch returns any key presses. This includes control characters, such as, say, the backspace character (ASCII 0x08):
http://en.wikipedia.org/wiki/ASCII

You might also want to do some input filtering to ensure that only characters you want accepted actually are (again, look at the ASCII table). Lastly, rather than go crazy with allowing the user to edit and change the password, you might want to consider using a "Please type password again", just to make sure the user is entering both the same.

Good luck!
 

What is "C++ Password character echo"?

"C++ Password character echo" is a feature in C++ programming that allows for the masking or echoing of characters entered by the user for password input. This helps to protect sensitive information from being easily visible on the screen.

How do I enable "C++ Password character echo" in my code?

To enable "C++ Password character echo" in your code, you can use the "getch()" function from the "conio.h" library. This function reads a single character from the keyboard without displaying it on the screen. You can also use the "getpass()" function from the "unistd.h" library, which prompts the user for a password and masks the input.

Can I customize the masking character for "C++ Password character echo"?

Yes, you can customize the masking character for "C++ Password character echo" by using the "system("stty -echo")" command before receiving input from the user. This will turn off the echo function and allow you to use any character of your choice for masking. Just remember to turn the echo function back on with the "system("stty echo")" command.

Is "C++ Password character echo" completely secure?

While "C++ Password character echo" does provide some level of security for password input, it is not completely secure. Skilled hackers can still potentially intercept and read the input before it is masked. It is always best practice to use additional methods of encryption and security for sensitive information.

Can I use "C++ Password character echo" for other types of input besides passwords?

Yes, "C++ Password character echo" can be used for any type of input that needs to be masked for security purposes. This can include sensitive data such as credit card numbers, social security numbers, and more. However, it is important to remember that it is not a foolproof method of protection and should be used in conjunction with other security measures.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
3
Views
2K
  • Programming and Computer Science
Replies
14
Views
31K
  • Engineering and Comp Sci Homework Help
Replies
5
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
5
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
3
Views
4K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
6K
  • Programming and Computer Science
Replies
13
Views
6K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
6K
  • Engineering and Comp Sci Homework Help
Replies
5
Views
2K
Back
Top