Click here to Skip to main content
15,889,831 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:

#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char u[10],p[10],user[]="lokesh",pas[]="spiderman";
int n=0;
clrscr();
printf("\n press enter and enter username and password(only
3 attempts)");
while(n<=2)
{
printf("\n Username: ");
scanf("%s",&u);
printf("\n Password: ");
scanf("%s",&p);
if(strcmp(user,u)==0 && strcmp(pas,p)==0)
{
printf("\n Congratulations!");
break;
}
else
{
n++;
printf("\n the username or password is incorrect. only %d
trials left. press enter", 3-n);
}
}
if(n==3)
{
printf("\n you have used maximum attempts(3). please try
later.");
}
getch();
}
Posted
Updated 12-Oct-17 5:45am
Comments
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)
 
Share this answer
 

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