Login functionality in C-language

dileepkumar235 0 Tallied Votes 4K Views Share

Login functionality in C-language :

Here the user enters the user id and password.

The entered user id and password will be compared with the stored ones and user will be authenticated.

While user enters password, characters should not be displayed on the screen.

user id comparison must be case insensitive and password must be case sensitive.

#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>
main()
{
int i,counter=0,flag=0;
char uid[25],pwd[25],s_uid[][25]={"11user1","12user2","13user3"};
char s_pwd[][25]={"Pwd1","Pwd2","Pwd3"},ch='a';/*dummy character in ch */
 clrscr();
printf("\n Enter the user id : ");
scanf("%s",uid);

printf("\n Enter the password : ");
i=0;
while(1)
{
	ch=getch();
	if(ch==13)
	break;
	else if(ch==8)
	{       if(i!=0) /*this is for avoiding the ENTER instructions getting deleted */
		{
			printf("\b");  /*printing backspace to move cursor 1 pos back*/
			printf("%c",32);/*making the char invisible which is already on console*/
			printf("\b"); /*printing backspace to move cursor 1 pos back*/
			i--;
			pwd[i]='\0';
		}
		else
		continue;

	}
	else
	{
	putchar('*');/* char - '*' will be printed instead of the character */
	pwd[i]=ch;
	i++;
	}
}
pwd[i]='\0';


for(i=0;i<=2;i++)
{
	if((stricmp(uid,s_uid[i]))==0 && (strcmp(pwd,s_pwd[i]))==0)
	{
		flag=1;
		break;
	}
}
if(flag) printf(" \n \n \t \t USER AUTHENTICATED ");
else printf("\n \n \n\t TRESSPASSERS WILL BE SHOT AND SURVIVORS WILL BE SHOT AGAIN .. ha ha :)");
printf(" \n \n \tThanks for testing.. written by dileep basam :) ");
getch();
}
eswarsure 0 Newbie Poster

your code is very good .
but if u provide one screenshot. it will be excellent
any way thank you

dileepkumar235 -5 Newbie Poster

hi eswar.. thanks for your feedback..
do u want the screenshot of the console ?

rambotan 0 Newbie Poster

i can't get. what is the id and pass. i am just a beginner.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

what is the id and pass.

They're hard coded:

11user1 = Pwd1
12user2 = Pwd2
13user3 = Pwd3

Lucaci Andrew 140 Za s|n

i can't get. what is the id and pass.

They are on line 8 and 9:

char uid[25],pwd[25],s_uid[][25]={"11user1","12user2","13user3"};
char s_pwd[][25]={"Pwd1","Pwd2","Pwd3"},ch='a';/*dummy character in ch */
Tanmay_1 0 Newbie Poster
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>
main()
{
int i,counter=0,flag=0;
char uid[25],pwd[25],s_uid[][25]={"11user1","12user2","13user3"};
char s_pwd[][25]={"Pwd1","Pwd2","Pwd3"},ch='a';/*dummy character in ch */
 clrscr();
printf("\n Enter the user id : ");
scanf("%s",uid);
printf("\n Enter the password : ");
i=0;
while(1)
{
    ch=getch();
    if(ch==13)
    break;
    else if(ch==8)
    {       if(i!=0) /*this is for avoiding the ENTER instructions getting deleted */
        {
            printf("\b");  /*printing backspace to move cursor 1 pos back*/
            printf("%c",32);/*making the char invisible which is already on console*/
            printf("\b"); /*printing backspace to move cursor 1 pos back*/
            i--;
            pwd[i]='\0';
        }
        else
        continue;
    }
    else
    {
    putchar('*');/* char - '*' will be printed instead of the character */
    pwd[i]=ch;
    i++;
    }
}
pwd[i]='\0';
for(i=0;i<=2;i++)
{
    if((stricmp(uid,s_uid[i]))==0 && (strcmp(pwd,s_pwd[i]))==0)
    {
        flag=1;
        break;
    }
}
if(flag) printf(" \n \n \t \t USER AUTHENTICATED ");
else printf("\n \n \n\t TRESSPASSERS WILL BE SHOT AND SURVIVORS WILL BE SHOT AGAIN .. ha ha :)");
printf(" \n \n \tThanks for testing.. written by dileep basam :) ");
getch();
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.