To start with, just the basic input without echo (which i think is getch()?), being able to delete characters and the storage they are kept in (vector maybe?) and i'll doing checking and what not myself.
Btw this won't be made to send passwords to a file or anything like that, its mainly the actual input i'm interested in at the moment.
If you don't care too much about security, you can just use getch() to read characters into a buffer to make up a string password. Then you can compare that to some held password somewhere with strcmp().
How much you care about security determines how much more complicated it is. For example, if you don't want your password showing up in a core dump, you want to hold an encrypted version, which means encrypting what's read and comparing those instead. And so on.
The ~ gives a bitwise inverse of the given value. For example, a byte holds eight bits.
00000010 This is the bit pattern for the number '2'
invert it
11111101 This is the bit pattern for the number '253' (unsigned) or '-3' (signed, two's complement)
This is useful when manipulating bit masks.
For example, suppose you want to turn off bit 2 (the third bit) in the values
00101100 Bit two is set
00101000 Bit two is clear
The code to do so is the same no matter what the current state of the bit to clear: value = value & ~(0x04);
So, in the code you indicated, I am removing the bits for 'echo' and 'line-buffered' input from the input mode mask. That means that input characters do not echo to the output display, nor must the user press the ENTER key before the input is sent to the program -- each key press is immediately available to the program.
The input buffer is nothing more than a string that caches input to your program.
Hope this helps.
[edit]
BTW, in response to the star question... The '\b' character only causes the cursor to back up one character. It doesn't remove any previous input. That's why in my password function the output sequence is "\b \b" -- back up, print a space, and back up again.
BTW, in response to the star question... The '\b' character only causes the cursor to back up one character. It doesn't remove any previous input. That's why in my password function the output sequence is "\b \b" -- back up, print a space, and back up again.
You literally read my mind! I was going to post that until I saw your code "\b \b" I misunderstood what the "\b" actually did. When tutorials say its a backspace I thought it meant the type of backspace that would occur if you was using a word processor e.g. you would go back one space and remove anything that was occupying that space. But now I realise it doesn't, it literally means go back one space!