Monday, August 4, 2014

C Program to Illustrate how User Authentication is Done

This C Program illustrate how user authentication is done. The program accepts the username and password. It checks whether the password is correct with respect to the username.
Here is source code of the C program to illustrate user authentication. The C program is successfully compiled and run on a Linux system. The program output is also shown below.
  1. /*
  2.  * C program is to illustrate how user authentication is done.
  3.  * Program asks for the user name and password and displays
  4.  * the password as '*' character
  5.  */
  6. #include <stdio.h>
  7.  
  8. void main()
  9. {
  10.  char password[10], username[10], ch;
  11.  int i;
  12.  
  13.  printf("Enter User name: ");
  14.  gets(username);
  15.  printf("Enter the password < any 8 characters>: ");
  16.  for (i = 0; i < 8; i++)
  17.  {
  18.             ch = getchar();
  19.             password[i] = ch;
  20.             ch = '*' ;
  21.             printf("%c", ch);
  22.  }
  23.         password[i] = '\0';
  24.  /*  Original password can be printed, if needed */
  25.  printf("\n Your password is :");
  26.  for (i = 0; i < 8; i++)
  27.  {
  28.             printf("%c", password[i]);
  29.  }
  30. }

$ cc pgm43.c
$ a.out
Enter User name: rajaraman
Enter the password <any 8 characters>: shashi12
********
Your password is :shashi12

No comments:

Post a Comment