Click here to Skip to main content
14,929,864 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I need a log in system that has a 3 attempts log in, and the password should be "*"

Please help me. I have a code here but i dont know how to input a password to "*" Please help.

What I have tried:

void main()
char u[10],p[10],user[]="lokesh",pas[]="spiderman";
int n=0;
printf("\n press enter and enter username and password(only
3 attempts)");
printf("\n Username: ");
printf("\n Password: ");
if(strcmp(user,u)==0 && strcmp(pas,p)==0)
printf("\n Congratulations!");
printf("\n the username or password is incorrect. only %d
trials left. press enter", 3-n);
printf("\n you have used maximum attempts(3). please try
Updated 12-Oct-17 5:45am
Jochen Arndt 29-Mar-17 7:24am
I guess that you should display a '*' for each entered character.

Then you can't use scanf(). You have to read the input char by char using getch() and store the characters until the Return key is pressed. While doing so print a '*' after each key press if not the Return key.

Because this looks like homework I will not provide code.
hesiod zxcv 29-Mar-17 7:44am
Yes this is my homework, i will try to understand your comment. Sir im a newbie in programming.. Thank you

1 solution

A nice pasword implementation which works as Jochen proposed, but with other function. (to close the Q&A)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900