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

  • Context: Comp Sci 
  • Thread starter Thread starter Deathfish
  • Start date Start date
  • Tags Tags
    C++ Echo
Click For Summary
SUMMARY

The best way to create a secure password prompt in C++ involves using the `getch()` function from `conio.h` to capture user input without displaying it on the screen. The implementation requires handling backspace and delete operations to allow users to edit their input. The password should be stored in a character array capable of accommodating up to 100 passwords, and it is essential to filter input based on ASCII values to ensure only valid characters are accepted. Additionally, prompting the user to re-enter the password can enhance security by confirming the input.

PREREQUISITES
  • Understanding of C++ programming language
  • Familiarity with `conio.h` for console input handling
  • Knowledge of ASCII character encoding
  • Experience with arrays in C++ for storing strings
NEXT STEPS
  • Implement input filtering based on ASCII values in C++
  • Explore advanced input handling techniques using `getch()`
  • Learn about secure password storage practices in C++
  • Research user interface best practices for password prompts
USEFUL FOR

C++ developers, software engineers focusing on secure application development, and anyone interested in improving user input handling in console applications.

Deathfish
Messages
80
Reaction score
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
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!
 

Similar threads

  • · Replies 3 ·
Replies
3
Views
1K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 14 ·
Replies
14
Views
35K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 7 ·
Replies
7
Views
8K