View Single Post
Old Jun 28th, 2005, 5:53 PM   #1
Navid
Hobbyist Programmer
 
Navid's Avatar
 
Join Date: Feb 2005
Location: Canada
Posts: 187
Rep Power: 4 Navid is on a distinguished road
Send a message via MSN to Navid
Password Program

This is a program where you input a password, and for each char it prints a *.
But when the user presses backspace, it erases the unechoed char that was inputed, but not the *.

#include <stdio.h>

char pass[10];
int count=0;

int main(void)
{
printf("Enter new password (10 characters max):");

while ( (pass[count++]=getch()) != '\r')
{

if(count > 10)
{
for (count=0; count<10; count++)
{
pass[count] = '\0';
}
printf("\n\nYour password is too long, enter it again:");
count = 0;
continue;
}
else
{
if (pass[count-1] == '\b' && count==1)
{
count=0;
continue;
}
else
{
if (pass[count-1] == '\b')
{
printf("\b");
count -= 2;
}
else
{
printf("*");
}
}
}

}
puts("\n\nYour new password is:");puts(pass);
printf("\n");
system("pause");
return 0;
}

So what should I do so it erases the * when the user presses backspace?
Navid is offline   Reply With Quote